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 11 pull requests #86457

Closed
wants to merge 27 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
6288aad
Stabilize span_open() and span_close().
m-ou-se Jun 8, 2021
e4b3131
Use as_secs_f64 in JunitFormatter
fee1-dead Jun 16, 2021
210e46b
Add pattern walking support to THIR walker
syvb Jun 16, 2021
68f9172
Fix rustdoc stabilized versions layout
Jun 17, 2021
7cadf7b
Alter std::cell::Cell::get_mut documentation
Eosis Jun 17, 2021
1d5acca
simplify borrowing
syvb Jun 17, 2021
281dd6d
Explicitly write out all fields
syvb Jun 17, 2021
382ba79
Use `map_or` instead of open-coding it
LingMan Jun 17, 2021
88abd7d
Lint for unused borrows as part of UNUSED_MUST_USE
Rustin170506 Jun 18, 2021
d7bb746
Make clippy tests happy
Rustin170506 Jun 18, 2021
884336e
Address comment
Rustin170506 Jun 18, 2021
f6adaed
add various coments to explain how the code works
nikomatsakis Jun 18, 2021
8776b0f
Update library tracking issue for libs-api rename.
m-ou-se Jun 18, 2021
e7a1186
Fix ICE with `#[repr(simd)]` on enum
FabianWolff Jun 18, 2021
831759a
fix typos
nikomatsakis Jun 18, 2021
c688e70
Fixed typo `BorroeError` => `BorrowError` in RefCell docs
akiselev Jun 19, 2021
488a068
Rollup merge of #86136 - m-ou-se:proc-macro-open-close-span, r=m-ou-se
Dylan-DPC Jun 19, 2021
212f703
Rollup merge of #86359 - fee1-dead:f64-junit-formatter, r=JohnTitor
Dylan-DPC Jun 19, 2021
6b7ea65
Rollup merge of #86370 - matteo-briani:fix-rustdoc-stabilized-version…
Dylan-DPC Jun 19, 2021
f1a7e01
Rollup merge of #86378 - Smittyvb:thir-walker-pat, r=LeSeulArtichaut
Dylan-DPC Jun 19, 2021
d55300b
Rollup merge of #86397 - Eosis:alter-cell-docs, r=JohnTitor
Dylan-DPC Jun 19, 2021
28a11f6
Rollup merge of #86407 - LingMan:map-or, r=LeSeulArtichaut
Dylan-DPC Jun 19, 2021
82ef6c8
Rollup merge of #86426 - hi-rustin:rustin-patch-lint-warn, r=Aaron1011
Dylan-DPC Jun 19, 2021
aa4a77f
Rollup merge of #86437 - nikomatsakis:tait-docs, r=oli-obk
Dylan-DPC Jun 19, 2021
a9fd8cd
Rollup merge of #86440 - rust-lang:libs-api-issue-template, r=m-ou-se
Dylan-DPC Jun 19, 2021
15c06b2
Rollup merge of #86444 - FabianWolff:issue-83505, r=LeSeulArtichaut
Dylan-DPC Jun 19, 2021
5f90563
Rollup merge of #86453 - akiselev:patch-1, r=dtolnay
Dylan-DPC Jun 19, 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
4 changes: 2 additions & 2 deletions .github/ISSUE_TEMPLATE/library_tracking_issue.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
name: Library Tracking Issue
about: A tracking issue for an unstable library feature.
title: Tracking Issue for XXX
labels: C-tracking-issue, T-libs
labels: C-tracking-issue, T-libs-api
---
<!--
Thank you for creating a tracking issue!
Expand Down Expand Up @@ -60,7 +60,7 @@ unresolved questions left, the feature might be ready for stabilization.
If this feature didn't go through the RFC process, a final commenting period
(FCP) is always needed before stabilization. This works as follows:

A library team member can kick off the stabilization process, at which point
A library API team member can kick off the stabilization process, at which point
the rfcbot will ask all the team members to verify they agree with
stabilization. Once enough members agree and there are no concerns, the final
commenting period begins: this issue will be marked as such and will be listed
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_lint/src/unused.rs
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ impl<'tcx> LateLintPass<'tcx> for UnusedResults {
| hir::BinOpKind::Shl
| hir::BinOpKind::Shr => Some("bitwise operation"),
},
hir::ExprKind::AddrOf(..) => Some("borrow"),
hir::ExprKind::Unary(..) => Some("unary operation"),
_ => None,
};
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_macros/src/hash_stable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ pub fn hash_stable_generic_derive(mut s: synstructure::Structure<'_>) -> proc_ma
quote! {}
} else if let Some(project) = attrs.project {
quote! {
&#bi.#project.hash_stable(__hcx, __hasher);
(&#bi.#project).hash_stable(__hcx, __hasher);
}
} else {
quote! {
Expand Down Expand Up @@ -96,7 +96,7 @@ pub fn hash_stable_derive(mut s: synstructure::Structure<'_>) -> proc_macro2::To
quote! {}
} else if let Some(project) = attrs.project {
quote! {
&#bi.#project.hash_stable(__hcx, __hasher);
(&#bi.#project).hash_stable(__hcx, __hasher);
}
} else {
quote! {
Expand Down
28 changes: 28 additions & 0 deletions compiler/rustc_middle/src/ty/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,34 @@ pub struct TypeckResults<'tcx> {
/// (including late-bound regions) are replaced with free
/// equivalents. This table is not used in codegen (since regions
/// are erased there) and hence is not serialized to metadata.
///
/// This table also contains the "revealed" values for any `impl Trait`
/// that appear in the signature and whose values are being inferred
/// by this function.
///
/// # Example
///
/// ```rust
/// fn foo(x: &u32) -> impl Debug { *x }
/// ```
///
/// The function signature here would be:
///
/// ```
/// for<'a> fn(&'a u32) -> Foo
/// ```
///
/// where `Foo` is an opaque type created for this function.
///
///
/// The *liberated* form of this would be
///
/// ```
/// fn(&'a u32) -> u32
/// ```
///
/// Note that `'a` is not bound (it would be an `ReFree`) and
/// that the `Foo` opaque type is replaced by its hidden type.
liberated_fn_sigs: ItemLocalMap<ty::FnSig<'tcx>>,

/// For each FRU expression, record the normalized types of the fields
Expand Down
9 changes: 9 additions & 0 deletions compiler/rustc_middle/src/ty/layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -672,6 +672,15 @@ impl<'tcx> LayoutCx<'tcx, TyCtxt<'tcx>> {

// SIMD vector types.
ty::Adt(def, substs) if def.repr.simd() => {
if !def.is_struct() {
// Should have yielded E0517 by now.
tcx.sess.delay_span_bug(
DUMMY_SP,
"#[repr(simd)] was applied to an ADT that is not a struct",
);
return Err(LayoutError::Unknown(ty));
}

// Supported SIMD vectors are homogeneous ADTs with at least one field:
//
// * #[repr(simd)] struct S(T, T, T, T);
Expand Down
57 changes: 55 additions & 2 deletions compiler/rustc_mir/src/borrow_check/type_check/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1206,6 +1206,36 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
Ok(())
}

/// Equates a type `anon_ty` that may contain opaque types whose
/// values are to be inferred by the MIR with def-id `anon_owner_def_id`.
///
/// The type `revealed_ty` contains the same type as `anon_ty`, but with the
/// hidden types for impl traits revealed.
///
/// # Example
///
/// Consider a piece of code like
///
/// ```rust
/// type Foo<U> = impl Debug;
///
/// fn foo<T: Debug>(t: T) -> Box<Foo<T>> {
/// Box::new((t, 22_u32))
/// }
/// ```
///
/// Here, the function signature would be something like
/// `fn(T) -> Box<impl Debug>`. The MIR return slot would have
/// the type with the opaque type revealed, so `Box<(T, u32)>`.
///
/// In terms of our function parameters:
///
/// * `anon_ty` would be `Box<Foo<T>>` where `Foo<T>` is an opaque type
/// scoped to this function (note that it is parameterized by the
/// generics of `foo`). Note that `anon_ty` is not just the opaque type,
/// but the entire return type (which may contain opaque types within it).
/// * `revealed_ty` would be `Box<(T, u32)>`
/// * `anon_owner_def_id` would be the def-id of `foo`
fn eq_opaque_type_and_type(
&mut self,
revealed_ty: Ty<'tcx>,
Expand Down Expand Up @@ -1240,6 +1270,8 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
let tcx = infcx.tcx;
let param_env = self.param_env;
let body = self.body;

// the "concrete opaque types" maps
let concrete_opaque_types = &tcx.typeck(anon_owner_def_id).concrete_opaque_types;
let mut opaque_type_values = VecMap::new();

Expand All @@ -1252,6 +1284,13 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
let mut obligations = ObligationAccumulator::default();

let dummy_body_id = hir::CRATE_HIR_ID;

// Replace the opaque types defined by this function with
// inference variables, creating a map. In our example above,
// this would transform the type `Box<Foo<T>>` (where `Foo` is an opaque type)
// to `Box<?T>`, returning an `opaque_type_map` mapping `{Foo<T> -> ?T}`.
// (Note that the key of the map is both the def-id of `Foo` along with
// any generic parameters.)
let (output_ty, opaque_type_map) =
obligations.add(infcx.instantiate_opaque_types(
anon_owner_def_id,
Expand All @@ -1267,6 +1306,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
revealed_ty={:?}",
output_ty, opaque_type_map, revealed_ty
);

// Make sure that the inferred types are well-formed. I'm
// not entirely sure this is needed (the HIR type check
// didn't do this) but it seems sensible to prevent opaque
Expand All @@ -1282,6 +1322,9 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
.eq(output_ty, revealed_ty)?,
);

// For each opaque type `Foo<T>` inferred by this value, we want to equate
// the inference variable `?T` with the revealed type that was computed
// earlier by type check.
for &(opaque_type_key, opaque_decl) in &opaque_type_map {
let resolved_ty = infcx.resolve_vars_if_possible(opaque_decl.concrete_ty);
let concrete_is_opaque = if let ty::Opaque(def_id, _) = resolved_ty.kind() {
Expand All @@ -1290,6 +1333,9 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
false
};

// The revealed type computed by the earlier phase of type check.
// In our example, this would be `(U, u32)`. Note that this references
// the type parameter `U` from the definition of `Foo`.
let concrete_ty = match concrete_opaque_types
.get_by(|(key, _)| key.def_id == opaque_type_key.def_id)
{
Expand All @@ -1308,7 +1354,13 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
Some(concrete_ty) => concrete_ty,
};
debug!("concrete_ty = {:?}", concrete_ty);

// Apply the substitution, in this case `[U -> T]`, so that the
// concrete type becomes `Foo<(T, u32)>`
let subst_opaque_defn_ty = concrete_ty.subst(tcx, opaque_type_key.substs);

// "Renumber" this, meaning that we replace all the regions
// with fresh inference variables. Not relevant to our example.
let renumbered_opaque_defn_ty =
renumber::renumber_regions(infcx, subst_opaque_defn_ty);

Expand All @@ -1318,8 +1370,9 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
);

if !concrete_is_opaque {
// Equate concrete_ty (an inference variable) with
// the renumbered type from typeck.
// Equate the instantiated opaque type `opaque_decl.concrete_ty` (`?T`,
// in our example) with the renumbered version that we took from
// the type check results (`Foo<(T, u32)>`).
obligations.add(
infcx
.at(&ObligationCause::dummy(), param_env)
Expand Down
9 changes: 3 additions & 6 deletions compiler/rustc_mir/src/transform/const_prop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1205,12 +1205,9 @@ impl<'mir, 'tcx> MutVisitor<'tcx> for ConstPropagator<'mir, 'tcx> {
let mut eval_to_int = |op| {
// This can be `None` if the lhs wasn't const propagated and we just
// triggered the assert on the value of the rhs.
match self.eval_operand(op, source_info) {
Some(op) => DbgVal::Val(
self.ecx.read_immediate(&op).unwrap().to_const_int(),
),
None => DbgVal::Underscore,
}
self.eval_operand(op, source_info).map_or(DbgVal::Underscore, |op| {
DbgVal::Val(self.ecx.read_immediate(&op).unwrap().to_const_int())
})
};
let msg = match msg {
AssertKind::DivisionByZero(op) => {
Expand Down
55 changes: 53 additions & 2 deletions compiler/rustc_mir_build/src/thir/visit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ pub trait Visitor<'a, 'tcx: 'a>: Sized {
walk_arm(self, arm);
}

fn visit_pat(&mut self, pat: &Pat<'tcx>) {
walk_pat(self, pat);
}

fn visit_const(&mut self, _cnst: &'tcx Const<'tcx>) {}
}

Expand Down Expand Up @@ -155,12 +159,13 @@ pub fn walk_stmt<'a, 'tcx: 'a, V: Visitor<'a, 'tcx>>(visitor: &mut V, stmt: &Stm
initializer,
remainder_scope: _,
init_scope: _,
pattern: _,
ref pattern,
lint_level: _,
} => {
if let Some(init) = initializer {
visitor.visit_expr(&visitor.thir()[init]);
}
visitor.visit_pat(pattern);
}
}
}
Expand All @@ -177,10 +182,56 @@ pub fn walk_block<'a, 'tcx: 'a, V: Visitor<'a, 'tcx>>(visitor: &mut V, block: &B
pub fn walk_arm<'a, 'tcx: 'a, V: Visitor<'a, 'tcx>>(visitor: &mut V, arm: &Arm<'tcx>) {
match arm.guard {
Some(Guard::If(expr)) => visitor.visit_expr(&visitor.thir()[expr]),
Some(Guard::IfLet(ref _pat, expr)) => {
Some(Guard::IfLet(ref pat, expr)) => {
visitor.visit_pat(pat);
visitor.visit_expr(&visitor.thir()[expr]);
}
None => {}
}
visitor.visit_pat(&arm.pattern);
visitor.visit_expr(&visitor.thir()[arm.body]);
}

pub fn walk_pat<'a, 'tcx: 'a, V: Visitor<'a, 'tcx>>(visitor: &mut V, pat: &Pat<'tcx>) {
use PatKind::*;
match pat.kind.as_ref() {
AscribeUserType { subpattern, ascription: _ }
| Deref { subpattern }
| Binding {
subpattern: Some(subpattern),
mutability: _,
mode: _,
var: _,
ty: _,
is_primary: _,
name: _,
} => visitor.visit_pat(&subpattern),
Binding { .. } | Wild => {}
Variant { subpatterns, adt_def: _, substs: _, variant_index: _ } | Leaf { subpatterns } => {
for subpattern in subpatterns {
visitor.visit_pat(&subpattern.pattern);
}
}
Constant { value } => visitor.visit_const(value),
Range(range) => {
visitor.visit_const(range.lo);
visitor.visit_const(range.hi);
}
Slice { prefix, slice, suffix } | Array { prefix, slice, suffix } => {
for subpattern in prefix {
visitor.visit_pat(&subpattern);
}
if let Some(pat) = slice {
visitor.visit_pat(pat);
}
for subpattern in suffix {
visitor.visit_pat(&subpattern);
}
}
Or { pats } => {
for pat in pats {
visitor.visit_pat(&pat);
}
}
};
}
12 changes: 3 additions & 9 deletions compiler/rustc_trait_selection/src/opaque_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ use rustc_data_structures::sync::Lrc;
use rustc_data_structures::vec_map::VecMap;
use rustc_hir as hir;
use rustc_hir::def_id::{DefId, LocalDefId};
use rustc_hir::Node;
use rustc_infer::infer::error_reporting::unexpected_hidden_region_diagnostic;
use rustc_infer::infer::free_regions::FreeRegionRelations;
use rustc_infer::infer::type_variable::{TypeVariableOrigin, TypeVariableOriginKind};
Expand Down Expand Up @@ -982,8 +981,8 @@ impl<'a, 'tcx> Instantiator<'a, 'tcx> {
let opaque_parent_hir_id = tcx.hir().get_parent_item(opaque_hir_id);
parent_def_id == tcx.hir().local_def_id(opaque_parent_hir_id)
};
let (in_definition_scope, origin) = match tcx.hir().find(opaque_hir_id) {
Some(Node::Item(item)) => match item.kind {
let (in_definition_scope, origin) =
match tcx.hir().expect_item(opaque_hir_id).kind {
// Anonymous `impl Trait`
hir::ItemKind::OpaqueTy(hir::OpaqueTy {
impl_trait_fn: Some(parent),
Expand All @@ -1000,12 +999,7 @@ impl<'a, 'tcx> Instantiator<'a, 'tcx> {
origin,
),
_ => (def_scope_default(), hir::OpaqueTyOrigin::Misc),
},
_ => bug!(
"expected item, found {}",
tcx.hir().node_to_string(opaque_hir_id),
),
};
};
if in_definition_scope {
let opaque_type_key =
OpaqueTypeKey { def_id: def_id.to_def_id(), substs };
Expand Down
10 changes: 5 additions & 5 deletions library/alloc/tests/str.rs
Original file line number Diff line number Diff line change
Expand Up @@ -534,7 +534,7 @@ mod slice_index {
#[test]
#[should_panic]
fn test_slice_fail() {
&"中华Việt Nam"[0..2];
let _ = &"中华Việt Nam"[0..2];
}

panic_cases! {
Expand Down Expand Up @@ -714,13 +714,13 @@ mod slice_index {
#[test]
#[should_panic(expected = "byte index 1024 is out of bounds of `Lorem ipsum dolor sit amet")]
fn test_slice_fail_truncated_1() {
&LOREM_PARAGRAPH[..1024];
let _ = &LOREM_PARAGRAPH[..1024];
}
// check the truncation in the panic message
#[test]
#[should_panic(expected = "luctus, im`[...]")]
fn test_slice_fail_truncated_2() {
&LOREM_PARAGRAPH[..1024];
let _ = &LOREM_PARAGRAPH[..1024];
}
}

Expand All @@ -735,7 +735,7 @@ fn test_str_slice_rangetoinclusive_ok() {
#[should_panic]
fn test_str_slice_rangetoinclusive_notok() {
let s = "abcαβγ";
&s[..=3];
let _ = &s[..=3];
}

#[test]
Expand All @@ -751,7 +751,7 @@ fn test_str_slicemut_rangetoinclusive_ok() {
fn test_str_slicemut_rangetoinclusive_notok() {
let mut s = "abcαβγ".to_owned();
let s: &mut str = &mut s;
&mut s[..=3];
let _ = &mut s[..=3];
}

#[test]
Expand Down
Loading