Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rollup of 9 pull requests #88359

Closed
wants to merge 34 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
da25af2
Make spans for tuple patterns in E0023 more precise
camelid Aug 17, 2021
f1e8607
Don't stabilize creation of TryReserveError instances
kornelski Aug 21, 2021
d0b482a
Add more tuple pattern too many fields test cases
camelid Aug 18, 2021
0fa3b4f
Make E0023 spans even more precise
camelid Aug 18, 2021
02ed23c
Use an exhaustive match in `Node::ident()` and add docs
camelid Aug 18, 2021
08ceac8
Add cross-crate tuple field count error test
camelid Aug 21, 2021
19f4510
Bless tests
camelid Aug 22, 2021
820e268
handle ascription type op in NLL HRTB diagnostics
lqd Aug 23, 2021
7b0e564
Update NLL HRTB type ascription blessed expectations
lqd Aug 23, 2021
a216d66
type_implements_trait consider obligation failure on overflow
arora-aman Aug 25, 2021
6f5402e
Add primitive documentation to libcore
jyn514 Jul 6, 2021
b1de9bd
downgrade some logging
jyn514 Jul 11, 2021
64fe43c
Fix broken handling of primitive items
jyn514 Jul 11, 2021
dfedd33
Fix linkcheck issues
jyn514 Jul 13, 2021
41d815e
Don't forcibly fail linkchecking if there's a broken intra-doc link o…
jyn514 Aug 19, 2021
d7d122f
update docs for `type_implements_trait`
nikomatsakis Aug 25, 2021
88bcd44
trailing whitespace
nikomatsakis Aug 25, 2021
33c71ac
Add `c_size_t` and `c_ssize_t` to `std::os::raw`.
thomcc Aug 25, 2021
25406d5
Fix rustdoc tests on Windows
GuillaumeGomez Aug 25, 2021
8a6501d
Adjust spans
camelid Aug 25, 2021
5b25de5
Reference tracking issue
thomcc Aug 25, 2021
5df5659
Revert "Add type of a let tait test impl trait straight in let"
spastorino Aug 25, 2021
bb583f7
Add field types tait tests
spastorino Aug 25, 2021
4fcae2c
Add const and static TAIT tests
spastorino Aug 25, 2021
7e435ce
Fix linkchecker on windows (backslash issue)
GuillaumeGomez Aug 26, 2021
e948f31
Rollup merge of #87073 - jyn514:primitive-docs, r=GuillaumeGomez
GuillaumeGomez Aug 26, 2021
b0d21ba
Rollup merge of #88123 - camelid:tup-pat-precise-spans, r=estebank
GuillaumeGomez Aug 26, 2021
b937bd4
Rollup merge of #88216 - kornelski:from_layout_err, r=kennytm
GuillaumeGomez Aug 26, 2021
d3996cc
Rollup merge of #88270 - lqd:hrtb-type-ascription, r=nikomatsakis
GuillaumeGomez Aug 26, 2021
6fe3893
Rollup merge of #88320 - sexxi-goose:issue-88103, r=nikomatsakis
GuillaumeGomez Aug 26, 2021
6d18e94
Rollup merge of #88340 - thomcc:c_size_t, r=joshtriplett
GuillaumeGomez Aug 26, 2021
ff7dda4
Rollup merge of #88346 - spastorino:revert-type-of-a-let2, r=jackh726
GuillaumeGomez Aug 26, 2021
84e8622
Rollup merge of #88348 - spastorino:field-types-tait-test, r=oli-obk
GuillaumeGomez Aug 26, 2021
e302595
Rollup merge of #88349 - spastorino:const-static-types-tait-test, r=o…
GuillaumeGomez Aug 26, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 33 additions & 2 deletions compiler/rustc_hir/src/hir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3183,6 +3183,20 @@ pub enum Node<'hir> {
}

impl<'hir> Node<'hir> {
/// Get the identifier of this `Node`, if applicable.
///
/// # Edge cases
///
/// Calling `.ident()` on a [`Node::Ctor`] will return `None`
/// because `Ctor`s do not have identifiers themselves.
/// Instead, call `.ident()` on the parent struct/variant, like so:
///
/// ```ignore (illustrative)
/// ctor
/// .ctor_hir_id()
/// .and_then(|ctor_id| tcx.hir().find(tcx.hir().get_parent_node(ctor_id)))
/// .and_then(|parent| parent.ident())
/// ```
pub fn ident(&self) -> Option<Ident> {
match self {
Node::TraitItem(TraitItem { ident, .. })
Expand All @@ -3191,8 +3205,25 @@ impl<'hir> Node<'hir> {
| Node::Field(FieldDef { ident, .. })
| Node::Variant(Variant { ident, .. })
| Node::MacroDef(MacroDef { ident, .. })
| Node::Item(Item { ident, .. }) => Some(*ident),
_ => None,
| Node::Item(Item { ident, .. })
| Node::PathSegment(PathSegment { ident, .. }) => Some(*ident),
Node::Lifetime(lt) => Some(lt.name.ident()),
Node::GenericParam(p) => Some(p.name.ident()),
Node::Param(..)
| Node::AnonConst(..)
| Node::Expr(..)
| Node::Stmt(..)
| Node::Block(..)
| Node::Ctor(..)
| Node::Pat(..)
| Node::Binding(..)
| Node::Arm(..)
| Node::Local(..)
| Node::Visibility(..)
| Node::Crate(..)
| Node::Ty(..)
| Node::TraitRef(..)
| Node::Infer(..) => None,
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use rustc_middle::ty::{self, Ty, TyCtxt, TypeFoldable};
use rustc_span::Span;
use rustc_trait_selection::traits::query::type_op;
use rustc_trait_selection::traits::{SelectionContext, TraitEngineExt as _};
use rustc_traits::type_op_prove_predicate_with_span;
use rustc_traits::{type_op_ascribe_user_type_with_span, type_op_prove_predicate_with_span};

use std::fmt;
use std::rc::Rc;
Expand Down Expand Up @@ -104,10 +104,11 @@ impl<'tcx, T: Copy + fmt::Display + TypeFoldable<'tcx> + 'tcx> ToUniverseInfo<'t
impl<'tcx> ToUniverseInfo<'tcx>
for Canonical<'tcx, ty::ParamEnvAnd<'tcx, type_op::AscribeUserType<'tcx>>>
{
fn to_universe_info(self, _base_universe: ty::UniverseIndex) -> UniverseInfo<'tcx> {
// Ascribe user type isn't usually called on types that have different
// bound regions.
UniverseInfo::other()
fn to_universe_info(self, base_universe: ty::UniverseIndex) -> UniverseInfo<'tcx> {
UniverseInfo(UniverseInfoInner::TypeOp(Rc::new(AscribeUserTypeQuery {
canonical_query: self,
base_universe,
})))
}
}

Expand Down Expand Up @@ -267,6 +268,37 @@ where
}
}

struct AscribeUserTypeQuery<'tcx> {
canonical_query: Canonical<'tcx, ty::ParamEnvAnd<'tcx, type_op::AscribeUserType<'tcx>>>,
base_universe: ty::UniverseIndex,
}

impl TypeOpInfo<'tcx> for AscribeUserTypeQuery<'tcx> {
fn fallback_error(&self, tcx: TyCtxt<'tcx>, span: Span) -> DiagnosticBuilder<'tcx> {
// FIXME: This error message isn't great, but it doesn't show up in the existing UI tests,
// and is only the fallback when the nice error fails. Consider improving this some more.
tcx.sess.struct_span_err(span, "higher-ranked lifetime error")
}

fn base_universe(&self) -> ty::UniverseIndex {
self.base_universe
}

fn nice_error(
&self,
tcx: TyCtxt<'tcx>,
span: Span,
placeholder_region: ty::Region<'tcx>,
error_region: Option<ty::Region<'tcx>>,
) -> Option<DiagnosticBuilder<'tcx>> {
tcx.infer_ctxt().enter_with_canonical(span, &self.canonical_query, |ref infcx, key, _| {
let mut fulfill_cx = <dyn TraitEngine<'_>>::new(tcx);
type_op_ascribe_user_type_with_span(infcx, &mut *fulfill_cx, key, Some(span)).ok()?;
try_extract_error_from_fulfill_cx(fulfill_cx, infcx, placeholder_region, error_region)
})
}
}

fn try_extract_error_from_fulfill_cx<'tcx>(
mut fulfill_cx: Box<dyn TraitEngine<'tcx> + 'tcx>,
infcx: &InferCtxt<'_, 'tcx>,
Expand Down
6 changes: 5 additions & 1 deletion compiler/rustc_trait_selection/src/infer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ pub trait InferCtxtExt<'tcx> {
/// - the self type
/// - the *other* type parameters of the trait, excluding the self-type
/// - the parameter environment
///
/// Invokes `evaluate_obligation`, so in the event that evaluating
/// `Ty: Trait` causes overflow, EvaluatedToRecur (or EvaluatedToUnknown)
/// will be returned.
fn type_implements_trait(
&self,
trait_def_id: DefId,
Expand Down Expand Up @@ -117,7 +121,7 @@ impl<'cx, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'cx, 'tcx> {
recursion_depth: 0,
predicate: trait_ref.without_const().to_predicate(self.tcx),
};
self.evaluate_obligation_no_overflow(&obligation)
self.evaluate_obligation(&obligation).unwrap_or(traits::EvaluationResult::EvaluatedToErr)
}
}

Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_traits/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ mod normalize_erasing_regions;
mod normalize_projection_ty;
mod type_op;

pub use type_op::type_op_prove_predicate_with_span;
pub use type_op::{type_op_ascribe_user_type_with_span, type_op_prove_predicate_with_span};

use rustc_middle::ty::query::Providers;

Expand Down
48 changes: 34 additions & 14 deletions compiler/rustc_traits/src/type_op.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,18 +40,28 @@ fn type_op_ascribe_user_type<'tcx>(
canonicalized: Canonical<'tcx, ParamEnvAnd<'tcx, AscribeUserType<'tcx>>>,
) -> Result<&'tcx Canonical<'tcx, QueryResponse<'tcx, ()>>, NoSolution> {
tcx.infer_ctxt().enter_canonical_trait_query(&canonicalized, |infcx, fulfill_cx, key| {
let (param_env, AscribeUserType { mir_ty, def_id, user_substs }) = key.into_parts();

debug!(
"type_op_ascribe_user_type: mir_ty={:?} def_id={:?} user_substs={:?}",
mir_ty, def_id, user_substs
);
type_op_ascribe_user_type_with_span(infcx, fulfill_cx, key, None)
})
}

let mut cx = AscribeUserTypeCx { infcx, param_env, fulfill_cx };
cx.relate_mir_and_user_ty(mir_ty, def_id, user_substs)?;
/// The core of the `type_op_ascribe_user_type` query: for diagnostics purposes in NLL HRTB errors,
/// this query can be re-run to better track the span of the obligation cause, and improve the error
/// message. Do not call directly unless you're in that very specific context.
pub fn type_op_ascribe_user_type_with_span<'a, 'tcx: 'a>(
infcx: &'a InferCtxt<'a, 'tcx>,
fulfill_cx: &'a mut dyn TraitEngine<'tcx>,
key: ParamEnvAnd<'tcx, AscribeUserType<'tcx>>,
span: Option<Span>,
) -> Result<(), NoSolution> {
let (param_env, AscribeUserType { mir_ty, def_id, user_substs }) = key.into_parts();
debug!(
"type_op_ascribe_user_type: mir_ty={:?} def_id={:?} user_substs={:?}",
mir_ty, def_id, user_substs
);

Ok(())
})
let mut cx = AscribeUserTypeCx { infcx, param_env, fulfill_cx };
cx.relate_mir_and_user_ty(mir_ty, def_id, user_substs, span)?;
Ok(())
}

struct AscribeUserTypeCx<'me, 'tcx> {
Expand Down Expand Up @@ -85,10 +95,15 @@ impl AscribeUserTypeCx<'me, 'tcx> {
Ok(())
}

fn prove_predicate(&mut self, predicate: Predicate<'tcx>) {
fn prove_predicate(&mut self, predicate: Predicate<'tcx>, span: Option<Span>) {
let cause = if let Some(span) = span {
ObligationCause::dummy_with_span(span)
} else {
ObligationCause::dummy()
};
self.fulfill_cx.register_predicate_obligation(
self.infcx,
Obligation::new(ObligationCause::dummy(), self.param_env, predicate),
Obligation::new(cause, self.param_env, predicate),
);
}

Expand All @@ -108,6 +123,7 @@ impl AscribeUserTypeCx<'me, 'tcx> {
mir_ty: Ty<'tcx>,
def_id: DefId,
user_substs: UserSubsts<'tcx>,
span: Option<Span>,
) -> Result<(), NoSolution> {
let UserSubsts { user_self_ty, substs } = user_substs;
let tcx = self.tcx();
Expand All @@ -129,7 +145,7 @@ impl AscribeUserTypeCx<'me, 'tcx> {
debug!(?instantiated_predicates.predicates);
for instantiated_predicate in instantiated_predicates.predicates {
let instantiated_predicate = self.normalize(instantiated_predicate);
self.prove_predicate(instantiated_predicate);
self.prove_predicate(instantiated_predicate, span);
}

if let Some(UserSelfTy { impl_def_id, self_ty }) = user_self_ty {
Expand All @@ -141,6 +157,7 @@ impl AscribeUserTypeCx<'me, 'tcx> {

self.prove_predicate(
ty::PredicateKind::WellFormed(impl_self_ty.into()).to_predicate(self.tcx()),
span,
);
}

Expand All @@ -155,7 +172,10 @@ impl AscribeUserTypeCx<'me, 'tcx> {
// them? This would only be relevant if some input
// type were ill-formed but did not appear in `ty`,
// which...could happen with normalization...
self.prove_predicate(ty::PredicateKind::WellFormed(ty.into()).to_predicate(self.tcx()));
self.prove_predicate(
ty::PredicateKind::WellFormed(ty.into()).to_predicate(self.tcx()),
span,
);
Ok(())
}
}
Expand Down
13 changes: 12 additions & 1 deletion compiler/rustc_ty_utils/src/ty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,18 @@ fn associated_items(tcx: TyCtxt<'_>, def_id: DefId) -> ty::AssocItems<'_> {
}

fn def_ident_span(tcx: TyCtxt<'_>, def_id: DefId) -> Option<Span> {
tcx.hir().get_if_local(def_id).and_then(|node| node.ident()).map(|ident| ident.span)
tcx.hir()
.get_if_local(def_id)
.and_then(|node| match node {
// A `Ctor` doesn't have an identifier itself, but its parent
// struct/variant does. Compare with `hir::Map::opt_span`.
hir::Node::Ctor(ctor) => ctor
.ctor_hir_id()
.and_then(|ctor_id| tcx.hir().find(tcx.hir().get_parent_node(ctor_id)))
.and_then(|parent| parent.ident()),
_ => node.ident(),
})
.map(|ident| ident.span)
}

/// If the given `DefId` describes an item belonging to a trait,
Expand Down
39 changes: 33 additions & 6 deletions compiler/rustc_typeck/src/check/pat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use rustc_span::hygiene::DesugaringKind;
use rustc_span::lev_distance::find_best_match_for_name;
use rustc_span::source_map::{Span, Spanned};
use rustc_span::symbol::Ident;
use rustc_span::{BytePos, DUMMY_SP};
use rustc_span::{BytePos, MultiSpan, DUMMY_SP};
use rustc_trait_selection::autoderef::Autoderef;
use rustc_trait_selection::traits::{ObligationCause, Pattern};
use ty::VariantDef;
Expand Down Expand Up @@ -990,10 +990,25 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
) {
let subpats_ending = pluralize!(subpats.len());
let fields_ending = pluralize!(fields.len());

let subpat_spans = if subpats.is_empty() {
vec![pat_span]
} else {
subpats.iter().map(|p| p.span).collect()
};
let last_subpat_span = *subpat_spans.last().unwrap();
let res_span = self.tcx.def_span(res.def_id());
let def_ident_span = self.tcx.def_ident_span(res.def_id()).unwrap_or(res_span);
let field_def_spans = if fields.is_empty() {
vec![res_span]
} else {
fields.iter().map(|f| f.ident.span).collect()
};
let last_field_def_span = *field_def_spans.last().unwrap();

let mut err = struct_span_err!(
self.tcx.sess,
pat_span,
MultiSpan::from_spans(subpat_spans.clone()),
E0023,
"this pattern has {} field{}, but the corresponding {} has {} field{}",
subpats.len(),
Expand All @@ -1003,10 +1018,22 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
fields_ending,
);
err.span_label(
pat_span,
format!("expected {} field{}, found {}", fields.len(), fields_ending, subpats.len(),),
)
.span_label(res_span, format!("{} defined here", res.descr()));
last_subpat_span,
&format!("expected {} field{}, found {}", fields.len(), fields_ending, subpats.len()),
);
if self.tcx.sess.source_map().is_multiline(qpath.span().between(last_subpat_span)) {
err.span_label(qpath.span(), "");
}
if self.tcx.sess.source_map().is_multiline(def_ident_span.between(last_field_def_span)) {
err.span_label(def_ident_span, format!("{} defined here", res.descr()));
}
for span in &field_def_spans[..field_def_spans.len() - 1] {
err.span_label(*span, "");
}
err.span_label(
last_field_def_span,
&format!("{} has {} field{}", res.descr(), fields.len(), fields_ending),
);

// Identify the case `Some(x, y)` where the expected type is e.g. `Option<(T, U)>`.
// More generally, the expected type wants a tuple variant with one field of an
Expand Down
6 changes: 3 additions & 3 deletions library/alloc/src/collections/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,12 +117,12 @@ impl From<TryReserveErrorKind> for TryReserveError {
}
}

#[unstable(feature = "try_reserve", reason = "new API", issue = "48043")]
impl From<LayoutError> for TryReserveError {
#[unstable(feature = "try_reserve_kind", reason = "new API", issue = "48043")]
impl From<LayoutError> for TryReserveErrorKind {
/// Always evaluates to [`TryReserveErrorKind::CapacityOverflow`].
#[inline]
fn from(_: LayoutError) -> Self {
TryReserveErrorKind::CapacityOverflow.into()
TryReserveErrorKind::CapacityOverflow
}
}

Expand Down
1 change: 1 addition & 0 deletions library/core/primitive_docs/box_into_raw.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
../std/boxed/struct.Box.html#method.into_raw
1 change: 1 addition & 0 deletions library/core/primitive_docs/fs_file.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
../std/fs/struct.File.html
1 change: 1 addition & 0 deletions library/core/primitive_docs/io_bufread.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
../std/io/trait.BufRead.html
1 change: 1 addition & 0 deletions library/core/primitive_docs/io_read.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
../std/io/trait.Read.html
1 change: 1 addition & 0 deletions library/core/primitive_docs/io_seek.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
../std/io/trait.Seek.html
1 change: 1 addition & 0 deletions library/core/primitive_docs/io_write.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
../std/io/trait.Write.html
1 change: 1 addition & 0 deletions library/core/primitive_docs/net_tosocketaddrs.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
../std/net/trait.ToSocketAddrs.html
1 change: 1 addition & 0 deletions library/core/primitive_docs/process_exit.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
../std/process/fn.exit.html
1 change: 1 addition & 0 deletions library/core/primitive_docs/string_string.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
../std/string/struct.String.html
2 changes: 1 addition & 1 deletion library/core/src/char/methods.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ impl char {
/// decoding error.
///
/// It can occur, for example, when giving ill-formed UTF-8 bytes to
/// [`String::from_utf8_lossy`](string/struct.String.html#method.from_utf8_lossy).
/// [`String::from_utf8_lossy`](../std/string/struct.String.html#method.from_utf8_lossy).
#[stable(feature = "assoc_char_consts", since = "1.52.0")]
pub const REPLACEMENT_CHARACTER: char = '\u{FFFD}';

Expand Down
3 changes: 3 additions & 0 deletions library/core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@
#![feature(decl_macro)]
#![feature(doc_cfg)]
#![feature(doc_notable_trait)]
#![cfg_attr(not(bootstrap), feature(doc_primitive))]
#![feature(exhaustive_patterns)]
#![feature(extern_types)]
#![feature(fundamental)]
Expand Down Expand Up @@ -357,3 +358,5 @@ pub mod arch {
/* compiler built-in */
}
}

include!("primitive_docs.rs");
Loading