Skip to content

Commit

Permalink
Auto merge of rust-lang#105196 - JohnTitor:rollup-8rxqnq6, r=JohnTitor
Browse files Browse the repository at this point in the history
Rollup of 7 pull requests

Successful merges:

 - rust-lang#104903 (Use ocx.normalize in report_projection_error)
 - rust-lang#105032 (improve doc of into_boxed_slice and impl From<Vec<T>> for Box<[T]>)
 - rust-lang#105100 (Add missing intra-doc link)
 - rust-lang#105181 (Don't add a note for implementing a trait if its inner type is erroneous)
 - rust-lang#105182 (Rustdoc-Json: Don't inline foreign traits)
 - rust-lang#105188 (Don't elide type information when printing E0308 with `-Zverbose`)
 - rust-lang#105189 (rustdoc: clean up redundant CSS on `.rustdoc-toggle.hideme`)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
  • Loading branch information
bors committed Dec 3, 2022
2 parents dd7a125 + d8f6cc3 commit 24f2704
Show file tree
Hide file tree
Showing 19 changed files with 259 additions and 111 deletions.
6 changes: 3 additions & 3 deletions compiler/rustc_infer/src/infer/error_reporting/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1255,7 +1255,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
let num_display_types = consts_offset - regions_len;
for (i, (ta1, ta2)) in type_arguments.take(num_display_types).enumerate() {
let i = i + regions_len;
if ta1 == ta2 {
if ta1 == ta2 && !self.tcx.sess.verbose() {
values.0.push_normal("_");
values.1.push_normal("_");
} else {
Expand All @@ -1271,7 +1271,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
let const_arguments = sub1.consts().zip(sub2.consts());
for (i, (ca1, ca2)) in const_arguments.enumerate() {
let i = i + consts_offset;
if ca1 == ca2 {
if ca1 == ca2 && !self.tcx.sess.verbose() {
values.0.push_normal("_");
values.1.push_normal("_");
} else {
Expand Down Expand Up @@ -1450,7 +1450,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
(ty::FnPtr(sig1), ty::FnPtr(sig2)) => self.cmp_fn_sig(sig1, sig2),

_ => {
if t1 == t2 {
if t1 == t2 && !self.tcx.sess.verbose() {
// The two types are the same, elide and don't highlight.
(DiagnosticStyledString::normal("_"), DiagnosticStyledString::normal("_"))
} else {
Expand Down
18 changes: 18 additions & 0 deletions compiler/rustc_trait_selection/src/traits/engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,24 @@ impl<'a, 'tcx> ObligationCtxt<'a, 'tcx> {
self.register_infer_ok_obligations(infer_ok)
}

/// Makes `expected <: actual`.
pub fn eq_exp<T>(
&self,
cause: &ObligationCause<'tcx>,
param_env: ty::ParamEnv<'tcx>,
a_is_expected: bool,
a: T,
b: T,
) -> Result<(), TypeError<'tcx>>
where
T: ToTrace<'tcx>,
{
self.infcx
.at(cause, param_env)
.eq_exp(a_is_expected, a, b)
.map(|infer_ok| self.register_infer_ok_obligations(infer_ok))
}

pub fn eq<T: ToTrace<'tcx>>(
&self,
cause: &ObligationCause<'tcx>,
Expand Down
51 changes: 30 additions & 21 deletions compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1577,32 +1577,26 @@ impl<'tcx> InferCtxtPrivExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
}

self.probe(|_| {
let mut err = error.err;
let mut values = None;
let ocx = ObligationCtxt::new_in_snapshot(self);

// try to find the mismatched types to report the error with.
//
// this can fail if the problem was higher-ranked, in which
// cause I have no idea for a good error message.
let bound_predicate = predicate.kind();
if let ty::PredicateKind::Clause(ty::Clause::Projection(data)) =
let (values, err) = if let ty::PredicateKind::Clause(ty::Clause::Projection(data)) =
bound_predicate.skip_binder()
{
let mut selcx = SelectionContext::new(self);
let data = self.replace_bound_vars_with_fresh_vars(
obligation.cause.span,
infer::LateBoundRegionConversionTime::HigherRankedType,
bound_predicate.rebind(data),
);
let mut obligations = vec![];
// FIXME(normalization): Change this to use `At::normalize`
let normalized_ty = super::normalize_projection_type(
&mut selcx,
let normalized_ty = ocx.normalize(
&obligation.cause,
obligation.param_env,
data.projection_ty,
obligation.cause.clone(),
0,
&mut obligations,
self.tcx
.mk_projection(data.projection_ty.item_def_id, data.projection_ty.substs),
);

debug!(?obligation.cause, ?obligation.param_env);
Expand All @@ -1618,19 +1612,34 @@ impl<'tcx> InferCtxtPrivExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
| ObligationCauseCode::ObjectCastObligation(..)
| ObligationCauseCode::OpaqueType
);
if let Err(new_err) = self.at(&obligation.cause, obligation.param_env).eq_exp(
let expected_ty = data.term.ty().unwrap();

// constrain inference variables a bit more to nested obligations from normalize so
// we can have more helpful errors.
ocx.select_where_possible();

if let Err(new_err) = ocx.eq_exp(
&obligation.cause,
obligation.param_env,
is_normalized_ty_expected,
normalized_ty,
data.term,
expected_ty,
) {
values = Some((data, is_normalized_ty_expected, normalized_ty, data.term));
err = new_err;
(Some((data, is_normalized_ty_expected, normalized_ty, expected_ty)), new_err)
} else {
(None, error.err)
}
}
} else {
(None, error.err)
};

let msg = values
.and_then(|(predicate, _, normalized_ty, expected_ty)| {
self.maybe_detailed_projection_msg(predicate, normalized_ty, expected_ty)
self.maybe_detailed_projection_msg(
predicate,
normalized_ty.into(),
expected_ty.into(),
)
})
.unwrap_or_else(|| format!("type mismatch resolving `{}`", predicate));
let mut diag = struct_span_err!(self.tcx.sess, obligation.cause.span, E0271, "{msg}");
Expand Down Expand Up @@ -1672,11 +1681,11 @@ impl<'tcx> InferCtxtPrivExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
&mut diag,
&obligation.cause,
secondary_span,
values.map(|(_, is_normalized_ty_expected, normalized_ty, term)| {
values.map(|(_, is_normalized_ty_expected, normalized_ty, expected_ty)| {
infer::ValuePairs::Terms(ExpectedFound::new(
is_normalized_ty_expected,
normalized_ty,
term,
normalized_ty.into(),
expected_ty.into(),
))
}),
err,
Expand Down
35 changes: 20 additions & 15 deletions compiler/rustc_trait_selection/src/traits/select/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -371,23 +371,28 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {

if !candidate_set.ambiguous && no_candidates_apply {
let trait_ref = stack.obligation.predicate.skip_binder().trait_ref;
let self_ty = trait_ref.self_ty();
let (trait_desc, self_desc) = with_no_trimmed_paths!({
let trait_desc = trait_ref.print_only_trait_path().to_string();
let self_desc = if self_ty.has_concrete_skeleton() {
Some(self_ty.to_string())
if !trait_ref.references_error() {
let self_ty = trait_ref.self_ty();
let (trait_desc, self_desc) = with_no_trimmed_paths!({
let trait_desc = trait_ref.print_only_trait_path().to_string();
let self_desc = if self_ty.has_concrete_skeleton() {
Some(self_ty.to_string())
} else {
None
};
(trait_desc, self_desc)
});
let cause = if let Conflict::Upstream = conflict {
IntercrateAmbiguityCause::UpstreamCrateUpdate {
trait_desc,
self_desc,
}
} else {
None
IntercrateAmbiguityCause::DownstreamCrate { trait_desc, self_desc }
};
(trait_desc, self_desc)
});
let cause = if let Conflict::Upstream = conflict {
IntercrateAmbiguityCause::UpstreamCrateUpdate { trait_desc, self_desc }
} else {
IntercrateAmbiguityCause::DownstreamCrate { trait_desc, self_desc }
};
debug!(?cause, "evaluate_stack: pushing cause");
self.intercrate_ambiguity_causes.as_mut().unwrap().insert(cause);
debug!(?cause, "evaluate_stack: pushing cause");
self.intercrate_ambiguity_causes.as_mut().unwrap().insert(cause);
}
}
}
}
Expand Down
11 changes: 10 additions & 1 deletion library/alloc/src/vec/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1070,7 +1070,8 @@ impl<T, A: Allocator> Vec<T, A> {

/// Converts the vector into [`Box<[T]>`][owned slice].
///
/// Note that this will drop any excess capacity.
/// If the vector has excess capacity, its items will be moved into a
/// newly-allocated buffer with exactly the right capacity.
///
/// [owned slice]: Box
///
Expand Down Expand Up @@ -3223,6 +3224,14 @@ impl<T, A: Allocator> From<Vec<T, A>> for Box<[T], A> {
/// ```
/// assert_eq!(Box::from(vec![1, 2, 3]), vec![1, 2, 3].into_boxed_slice());
/// ```
///
/// Any excess capacity is removed:
/// ```
/// let mut vec = Vec::with_capacity(10);
/// vec.extend([1, 2, 3]);
///
/// assert_eq!(Box::from(vec), vec![1, 2, 3].into_boxed_slice());
/// ```
fn from(v: Vec<T, A>) -> Self {
v.into_boxed_slice()
}
Expand Down
5 changes: 3 additions & 2 deletions library/std/src/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -510,8 +510,9 @@ impl File {
/// # Errors
///
/// This function will return an error if the file is not opened for writing.
/// Also, std::io::ErrorKind::InvalidInput will be returned if the desired
/// length would cause an overflow due to the implementation specifics.
/// Also, [`std::io::ErrorKind::InvalidInput`](crate::io::ErrorKind::InvalidInput)
/// will be returned if the desired length would cause an overflow due to
/// the implementation specifics.
///
/// # Examples
///
Expand Down
10 changes: 2 additions & 8 deletions src/librustdoc/html/static/css/rustdoc.css
Original file line number Diff line number Diff line change
Expand Up @@ -1585,17 +1585,11 @@ details.rustdoc-toggle[open] > summary.hideme > span {
display: none;
}

details.rustdoc-toggle[open] > summary::before,
details.rustdoc-toggle[open] > summary.hideme::before {
details.rustdoc-toggle[open] > summary::before {
background: url("toggle-minus-31bbd6e4c77f5c96.svg") no-repeat top left;
width: 16px;
height: 16px;
display: inline-block;
content: "";
}

details.rustdoc-toggle[open] > summary::after,
details.rustdoc-toggle[open] > summary.hideme::after {
details.rustdoc-toggle[open] > summary::after {
content: "Collapse";
}

Expand Down
53 changes: 1 addition & 52 deletions src/librustdoc/json/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,53 +99,6 @@ impl<'tcx> JsonRenderer<'tcx> {
})
.unwrap_or_default()
}

fn get_trait_items(&mut self) -> Vec<(types::Id, types::Item)> {
debug!("Adding foreign trait items");
Rc::clone(&self.cache)
.traits
.iter()
.filter_map(|(&id, trait_item)| {
// only need to synthesize items for external traits
if !id.is_local() {
for item in &trait_item.items {
trace!("Adding subitem to {id:?}: {:?}", item.item_id);
self.item(item.clone()).unwrap();
}
let item_id = from_item_id(id.into(), self.tcx);
Some((
item_id.clone(),
types::Item {
id: item_id,
crate_id: id.krate.as_u32(),
name: self
.cache
.paths
.get(&id)
.unwrap_or_else(|| {
self.cache
.external_paths
.get(&id)
.expect("Trait should either be in local or external paths")
})
.0
.last()
.map(|s| s.to_string()),
visibility: types::Visibility::Public,
inner: types::ItemEnum::Trait(trait_item.clone().into_tcx(self.tcx)),
span: None,
docs: Default::default(),
links: Default::default(),
attrs: Default::default(),
deprecation: Default::default(),
},
))
} else {
None
}
})
.collect()
}
}

impl<'tcx> FormatRenderer<'tcx> for JsonRenderer<'tcx> {
Expand Down Expand Up @@ -276,11 +229,7 @@ impl<'tcx> FormatRenderer<'tcx> for JsonRenderer<'tcx> {

let e = ExternalCrate { crate_num: LOCAL_CRATE };

// FIXME(adotinthevoid): Remove this, as it's not consistent with not
// inlining foreign items.
let foreign_trait_items = self.get_trait_items();
let mut index = (*self.index).clone().into_inner();
index.extend(foreign_trait_items);
let index = (*self.index).clone().into_inner();

debug!("Constructing Output");
// This needs to be the default HashMap for compatibility with the public interface for
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
pub trait Trait {
/// [`Enum::Variant`]
fn method() {}
}

pub enum Enum {
Variant,
}
13 changes: 13 additions & 0 deletions src/test/rustdoc-json/intra-doc-links/foreign_variant.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// Regression test for <https://github.com/rust-lang/rust/issues/105025>
// aux-build: enum_variant_in_trait_method.rs

extern crate enum_variant_in_trait_method;

pub struct Local;

/// local impl
impl enum_variant_in_trait_method::Trait for Local {}

// @!has "$.index[*][?(@.name == 'Trait')]"
// @!has "$.index[*][?(@.name == 'method')]"
// @count "$.index[*][?(@.docs == 'local impl')].inner.items[*]" 0
2 changes: 2 additions & 0 deletions src/test/rustdoc-json/reexport/auxiliary/trait_with_docs.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/// The Docs
pub trait HasDocs {}
10 changes: 10 additions & 0 deletions src/test/rustdoc-json/reexport/synthesize_trait_with_docs.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// Regression test for <https://github.com/rust-lang/rust/issues/105022>
// aux-build: trait_with_docs.rs

extern crate trait_with_docs;

pub struct Local;

impl trait_with_docs::HasDocs for Local {}

// @!has "$.index[*][?(@.name == 'HasDocs')]"
11 changes: 2 additions & 9 deletions src/test/rustdoc-json/traits/uses_extern_trait.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,5 @@
#![no_std]
pub fn drop_default<T: core::default::Default>(_x: T) {}

// FIXME(adotinthevoid): Theses shouldn't be here
// @has "$.index[*][?(@.name=='Debug')]"

// Debug may have several items. All we depend on here the that `fmt` is first. See
// https://github.com/rust-lang/rust/pull/104525#issuecomment-1331087852 for why we
// can't use [*].

// @set Debug_fmt = "$.index[*][?(@.name=='Debug')].inner.items[0]"
// @has "$.index[*][?(@.name=='fmt')].id" $Debug_fmt
// @!has "$.index[*][?(@.name=='Debug')]"
// @!has "$.index[*][?(@.name=='Default')]"
15 changes: 15 additions & 0 deletions src/test/ui/fn/signature-error-reporting-under-verbose.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// compile-flags: -Zverbose

fn foo(_: i32, _: i32) {}

fn needs_ptr(_: fn(i32, u32)) {}
//~^ NOTE function defined here
//~| NOTE

fn main() {
needs_ptr(foo);
//~^ ERROR mismatched types
//~| NOTE expected `u32`, found `i32`
//~| NOTE expected fn pointer `fn(i32, u32)`
//~| NOTE arguments to this function are incorrect
}
Loading

0 comments on commit 24f2704

Please sign in to comment.