Skip to content

Commit 24f2704

Browse files
committed
Auto merge of #105196 - JohnTitor:rollup-8rxqnq6, r=JohnTitor
Rollup of 7 pull requests Successful merges: - #104903 (Use ocx.normalize in report_projection_error) - #105032 (improve doc of into_boxed_slice and impl From<Vec<T>> for Box<[T]>) - #105100 (Add missing intra-doc link) - #105181 (Don't add a note for implementing a trait if its inner type is erroneous) - #105182 (Rustdoc-Json: Don't inline foreign traits) - #105188 (Don't elide type information when printing E0308 with `-Zverbose`) - #105189 (rustdoc: clean up redundant CSS on `.rustdoc-toggle.hideme`) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents dd7a125 + d8f6cc3 commit 24f2704

File tree

19 files changed

+259
-111
lines changed

19 files changed

+259
-111
lines changed

compiler/rustc_infer/src/infer/error_reporting/mod.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1255,7 +1255,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
12551255
let num_display_types = consts_offset - regions_len;
12561256
for (i, (ta1, ta2)) in type_arguments.take(num_display_types).enumerate() {
12571257
let i = i + regions_len;
1258-
if ta1 == ta2 {
1258+
if ta1 == ta2 && !self.tcx.sess.verbose() {
12591259
values.0.push_normal("_");
12601260
values.1.push_normal("_");
12611261
} else {
@@ -1271,7 +1271,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
12711271
let const_arguments = sub1.consts().zip(sub2.consts());
12721272
for (i, (ca1, ca2)) in const_arguments.enumerate() {
12731273
let i = i + consts_offset;
1274-
if ca1 == ca2 {
1274+
if ca1 == ca2 && !self.tcx.sess.verbose() {
12751275
values.0.push_normal("_");
12761276
values.1.push_normal("_");
12771277
} else {
@@ -1450,7 +1450,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
14501450
(ty::FnPtr(sig1), ty::FnPtr(sig2)) => self.cmp_fn_sig(sig1, sig2),
14511451

14521452
_ => {
1453-
if t1 == t2 {
1453+
if t1 == t2 && !self.tcx.sess.verbose() {
14541454
// The two types are the same, elide and don't highlight.
14551455
(DiagnosticStyledString::normal("_"), DiagnosticStyledString::normal("_"))
14561456
} else {

compiler/rustc_trait_selection/src/traits/engine.rs

+18
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,24 @@ impl<'a, 'tcx> ObligationCtxt<'a, 'tcx> {
112112
self.register_infer_ok_obligations(infer_ok)
113113
}
114114

115+
/// Makes `expected <: actual`.
116+
pub fn eq_exp<T>(
117+
&self,
118+
cause: &ObligationCause<'tcx>,
119+
param_env: ty::ParamEnv<'tcx>,
120+
a_is_expected: bool,
121+
a: T,
122+
b: T,
123+
) -> Result<(), TypeError<'tcx>>
124+
where
125+
T: ToTrace<'tcx>,
126+
{
127+
self.infcx
128+
.at(cause, param_env)
129+
.eq_exp(a_is_expected, a, b)
130+
.map(|infer_ok| self.register_infer_ok_obligations(infer_ok))
131+
}
132+
115133
pub fn eq<T: ToTrace<'tcx>>(
116134
&self,
117135
cause: &ObligationCause<'tcx>,

compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs

+30-21
Original file line numberDiff line numberDiff line change
@@ -1577,32 +1577,26 @@ impl<'tcx> InferCtxtPrivExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
15771577
}
15781578

15791579
self.probe(|_| {
1580-
let mut err = error.err;
1581-
let mut values = None;
1580+
let ocx = ObligationCtxt::new_in_snapshot(self);
15821581

15831582
// try to find the mismatched types to report the error with.
15841583
//
15851584
// this can fail if the problem was higher-ranked, in which
15861585
// cause I have no idea for a good error message.
15871586
let bound_predicate = predicate.kind();
1588-
if let ty::PredicateKind::Clause(ty::Clause::Projection(data)) =
1587+
let (values, err) = if let ty::PredicateKind::Clause(ty::Clause::Projection(data)) =
15891588
bound_predicate.skip_binder()
15901589
{
1591-
let mut selcx = SelectionContext::new(self);
15921590
let data = self.replace_bound_vars_with_fresh_vars(
15931591
obligation.cause.span,
15941592
infer::LateBoundRegionConversionTime::HigherRankedType,
15951593
bound_predicate.rebind(data),
15961594
);
1597-
let mut obligations = vec![];
1598-
// FIXME(normalization): Change this to use `At::normalize`
1599-
let normalized_ty = super::normalize_projection_type(
1600-
&mut selcx,
1595+
let normalized_ty = ocx.normalize(
1596+
&obligation.cause,
16011597
obligation.param_env,
1602-
data.projection_ty,
1603-
obligation.cause.clone(),
1604-
0,
1605-
&mut obligations,
1598+
self.tcx
1599+
.mk_projection(data.projection_ty.item_def_id, data.projection_ty.substs),
16061600
);
16071601

16081602
debug!(?obligation.cause, ?obligation.param_env);
@@ -1618,19 +1612,34 @@ impl<'tcx> InferCtxtPrivExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
16181612
| ObligationCauseCode::ObjectCastObligation(..)
16191613
| ObligationCauseCode::OpaqueType
16201614
);
1621-
if let Err(new_err) = self.at(&obligation.cause, obligation.param_env).eq_exp(
1615+
let expected_ty = data.term.ty().unwrap();
1616+
1617+
// constrain inference variables a bit more to nested obligations from normalize so
1618+
// we can have more helpful errors.
1619+
ocx.select_where_possible();
1620+
1621+
if let Err(new_err) = ocx.eq_exp(
1622+
&obligation.cause,
1623+
obligation.param_env,
16221624
is_normalized_ty_expected,
16231625
normalized_ty,
1624-
data.term,
1626+
expected_ty,
16251627
) {
1626-
values = Some((data, is_normalized_ty_expected, normalized_ty, data.term));
1627-
err = new_err;
1628+
(Some((data, is_normalized_ty_expected, normalized_ty, expected_ty)), new_err)
1629+
} else {
1630+
(None, error.err)
16281631
}
1629-
}
1632+
} else {
1633+
(None, error.err)
1634+
};
16301635

16311636
let msg = values
16321637
.and_then(|(predicate, _, normalized_ty, expected_ty)| {
1633-
self.maybe_detailed_projection_msg(predicate, normalized_ty, expected_ty)
1638+
self.maybe_detailed_projection_msg(
1639+
predicate,
1640+
normalized_ty.into(),
1641+
expected_ty.into(),
1642+
)
16341643
})
16351644
.unwrap_or_else(|| format!("type mismatch resolving `{}`", predicate));
16361645
let mut diag = struct_span_err!(self.tcx.sess, obligation.cause.span, E0271, "{msg}");
@@ -1672,11 +1681,11 @@ impl<'tcx> InferCtxtPrivExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
16721681
&mut diag,
16731682
&obligation.cause,
16741683
secondary_span,
1675-
values.map(|(_, is_normalized_ty_expected, normalized_ty, term)| {
1684+
values.map(|(_, is_normalized_ty_expected, normalized_ty, expected_ty)| {
16761685
infer::ValuePairs::Terms(ExpectedFound::new(
16771686
is_normalized_ty_expected,
1678-
normalized_ty,
1679-
term,
1687+
normalized_ty.into(),
1688+
expected_ty.into(),
16801689
))
16811690
}),
16821691
err,

compiler/rustc_trait_selection/src/traits/select/mod.rs

+20-15
Original file line numberDiff line numberDiff line change
@@ -371,23 +371,28 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
371371

372372
if !candidate_set.ambiguous && no_candidates_apply {
373373
let trait_ref = stack.obligation.predicate.skip_binder().trait_ref;
374-
let self_ty = trait_ref.self_ty();
375-
let (trait_desc, self_desc) = with_no_trimmed_paths!({
376-
let trait_desc = trait_ref.print_only_trait_path().to_string();
377-
let self_desc = if self_ty.has_concrete_skeleton() {
378-
Some(self_ty.to_string())
374+
if !trait_ref.references_error() {
375+
let self_ty = trait_ref.self_ty();
376+
let (trait_desc, self_desc) = with_no_trimmed_paths!({
377+
let trait_desc = trait_ref.print_only_trait_path().to_string();
378+
let self_desc = if self_ty.has_concrete_skeleton() {
379+
Some(self_ty.to_string())
380+
} else {
381+
None
382+
};
383+
(trait_desc, self_desc)
384+
});
385+
let cause = if let Conflict::Upstream = conflict {
386+
IntercrateAmbiguityCause::UpstreamCrateUpdate {
387+
trait_desc,
388+
self_desc,
389+
}
379390
} else {
380-
None
391+
IntercrateAmbiguityCause::DownstreamCrate { trait_desc, self_desc }
381392
};
382-
(trait_desc, self_desc)
383-
});
384-
let cause = if let Conflict::Upstream = conflict {
385-
IntercrateAmbiguityCause::UpstreamCrateUpdate { trait_desc, self_desc }
386-
} else {
387-
IntercrateAmbiguityCause::DownstreamCrate { trait_desc, self_desc }
388-
};
389-
debug!(?cause, "evaluate_stack: pushing cause");
390-
self.intercrate_ambiguity_causes.as_mut().unwrap().insert(cause);
393+
debug!(?cause, "evaluate_stack: pushing cause");
394+
self.intercrate_ambiguity_causes.as_mut().unwrap().insert(cause);
395+
}
391396
}
392397
}
393398
}

library/alloc/src/vec/mod.rs

+10-1
Original file line numberDiff line numberDiff line change
@@ -1070,7 +1070,8 @@ impl<T, A: Allocator> Vec<T, A> {
10701070

10711071
/// Converts the vector into [`Box<[T]>`][owned slice].
10721072
///
1073-
/// Note that this will drop any excess capacity.
1073+
/// If the vector has excess capacity, its items will be moved into a
1074+
/// newly-allocated buffer with exactly the right capacity.
10741075
///
10751076
/// [owned slice]: Box
10761077
///
@@ -3223,6 +3224,14 @@ impl<T, A: Allocator> From<Vec<T, A>> for Box<[T], A> {
32233224
/// ```
32243225
/// assert_eq!(Box::from(vec![1, 2, 3]), vec![1, 2, 3].into_boxed_slice());
32253226
/// ```
3227+
///
3228+
/// Any excess capacity is removed:
3229+
/// ```
3230+
/// let mut vec = Vec::with_capacity(10);
3231+
/// vec.extend([1, 2, 3]);
3232+
///
3233+
/// assert_eq!(Box::from(vec), vec![1, 2, 3].into_boxed_slice());
3234+
/// ```
32263235
fn from(v: Vec<T, A>) -> Self {
32273236
v.into_boxed_slice()
32283237
}

library/std/src/fs.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -510,8 +510,9 @@ impl File {
510510
/// # Errors
511511
///
512512
/// This function will return an error if the file is not opened for writing.
513-
/// Also, std::io::ErrorKind::InvalidInput will be returned if the desired
514-
/// length would cause an overflow due to the implementation specifics.
513+
/// Also, [`std::io::ErrorKind::InvalidInput`](crate::io::ErrorKind::InvalidInput)
514+
/// will be returned if the desired length would cause an overflow due to
515+
/// the implementation specifics.
515516
///
516517
/// # Examples
517518
///

src/librustdoc/html/static/css/rustdoc.css

+2-8
Original file line numberDiff line numberDiff line change
@@ -1585,17 +1585,11 @@ details.rustdoc-toggle[open] > summary.hideme > span {
15851585
display: none;
15861586
}
15871587

1588-
details.rustdoc-toggle[open] > summary::before,
1589-
details.rustdoc-toggle[open] > summary.hideme::before {
1588+
details.rustdoc-toggle[open] > summary::before {
15901589
background: url("toggle-minus-31bbd6e4c77f5c96.svg") no-repeat top left;
1591-
width: 16px;
1592-
height: 16px;
1593-
display: inline-block;
1594-
content: "";
15951590
}
15961591

1597-
details.rustdoc-toggle[open] > summary::after,
1598-
details.rustdoc-toggle[open] > summary.hideme::after {
1592+
details.rustdoc-toggle[open] > summary::after {
15991593
content: "Collapse";
16001594
}
16011595

src/librustdoc/json/mod.rs

+1-52
Original file line numberDiff line numberDiff line change
@@ -99,53 +99,6 @@ impl<'tcx> JsonRenderer<'tcx> {
9999
})
100100
.unwrap_or_default()
101101
}
102-
103-
fn get_trait_items(&mut self) -> Vec<(types::Id, types::Item)> {
104-
debug!("Adding foreign trait items");
105-
Rc::clone(&self.cache)
106-
.traits
107-
.iter()
108-
.filter_map(|(&id, trait_item)| {
109-
// only need to synthesize items for external traits
110-
if !id.is_local() {
111-
for item in &trait_item.items {
112-
trace!("Adding subitem to {id:?}: {:?}", item.item_id);
113-
self.item(item.clone()).unwrap();
114-
}
115-
let item_id = from_item_id(id.into(), self.tcx);
116-
Some((
117-
item_id.clone(),
118-
types::Item {
119-
id: item_id,
120-
crate_id: id.krate.as_u32(),
121-
name: self
122-
.cache
123-
.paths
124-
.get(&id)
125-
.unwrap_or_else(|| {
126-
self.cache
127-
.external_paths
128-
.get(&id)
129-
.expect("Trait should either be in local or external paths")
130-
})
131-
.0
132-
.last()
133-
.map(|s| s.to_string()),
134-
visibility: types::Visibility::Public,
135-
inner: types::ItemEnum::Trait(trait_item.clone().into_tcx(self.tcx)),
136-
span: None,
137-
docs: Default::default(),
138-
links: Default::default(),
139-
attrs: Default::default(),
140-
deprecation: Default::default(),
141-
},
142-
))
143-
} else {
144-
None
145-
}
146-
})
147-
.collect()
148-
}
149102
}
150103

151104
impl<'tcx> FormatRenderer<'tcx> for JsonRenderer<'tcx> {
@@ -276,11 +229,7 @@ impl<'tcx> FormatRenderer<'tcx> for JsonRenderer<'tcx> {
276229

277230
let e = ExternalCrate { crate_num: LOCAL_CRATE };
278231

279-
// FIXME(adotinthevoid): Remove this, as it's not consistent with not
280-
// inlining foreign items.
281-
let foreign_trait_items = self.get_trait_items();
282-
let mut index = (*self.index).clone().into_inner();
283-
index.extend(foreign_trait_items);
232+
let index = (*self.index).clone().into_inner();
284233

285234
debug!("Constructing Output");
286235
// This needs to be the default HashMap for compatibility with the public interface for
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
pub trait Trait {
2+
/// [`Enum::Variant`]
3+
fn method() {}
4+
}
5+
6+
pub enum Enum {
7+
Variant,
8+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// Regression test for <https://github.com/rust-lang/rust/issues/105025>
2+
// aux-build: enum_variant_in_trait_method.rs
3+
4+
extern crate enum_variant_in_trait_method;
5+
6+
pub struct Local;
7+
8+
/// local impl
9+
impl enum_variant_in_trait_method::Trait for Local {}
10+
11+
// @!has "$.index[*][?(@.name == 'Trait')]"
12+
// @!has "$.index[*][?(@.name == 'method')]"
13+
// @count "$.index[*][?(@.docs == 'local impl')].inner.items[*]" 0
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
/// The Docs
2+
pub trait HasDocs {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// Regression test for <https://github.com/rust-lang/rust/issues/105022>
2+
// aux-build: trait_with_docs.rs
3+
4+
extern crate trait_with_docs;
5+
6+
pub struct Local;
7+
8+
impl trait_with_docs::HasDocs for Local {}
9+
10+
// @!has "$.index[*][?(@.name == 'HasDocs')]"
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,5 @@
11
#![no_std]
22
pub fn drop_default<T: core::default::Default>(_x: T) {}
33

4-
// FIXME(adotinthevoid): Theses shouldn't be here
5-
// @has "$.index[*][?(@.name=='Debug')]"
6-
7-
// Debug may have several items. All we depend on here the that `fmt` is first. See
8-
// https://github.com/rust-lang/rust/pull/104525#issuecomment-1331087852 for why we
9-
// can't use [*].
10-
11-
// @set Debug_fmt = "$.index[*][?(@.name=='Debug')].inner.items[0]"
12-
// @has "$.index[*][?(@.name=='fmt')].id" $Debug_fmt
4+
// @!has "$.index[*][?(@.name=='Debug')]"
5+
// @!has "$.index[*][?(@.name=='Default')]"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// compile-flags: -Zverbose
2+
3+
fn foo(_: i32, _: i32) {}
4+
5+
fn needs_ptr(_: fn(i32, u32)) {}
6+
//~^ NOTE function defined here
7+
//~| NOTE
8+
9+
fn main() {
10+
needs_ptr(foo);
11+
//~^ ERROR mismatched types
12+
//~| NOTE expected `u32`, found `i32`
13+
//~| NOTE expected fn pointer `fn(i32, u32)`
14+
//~| NOTE arguments to this function are incorrect
15+
}

0 commit comments

Comments
 (0)