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 #88371

Merged
merged 34 commits into from
Aug 27, 2021
Merged
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
d933edd
Revert "Revert "Don't load all extern crates unconditionally""
jyn514 Aug 21, 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
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
0a42dfc
Fix debugger stepping behavior around `match` expressions
wesleywiser Jul 23, 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
84a2661
Add test for stepping though `match` expressions
wesleywiser Aug 6, 2021
4924e34
Add argument types tait tests
spastorino Aug 25, 2021
027db5d
RustWrapper: adapt to LLVM change 0f45c16f2caa
durin42 Aug 24, 2021
c60a370
Fix the bugs and add a regression test
jyn514 Aug 21, 2021
fb79597
Rollup merge of #87832 - wesleywiser:fix_match_step, r=davidtwco
Manishearth Aug 26, 2021
8aa46e5
Rollup merge of #88123 - camelid:tup-pat-precise-spans, r=estebank
Manishearth Aug 26, 2021
14fb87a
Rollup merge of #88215 - jyn514:lazy-loading, r=petrochenkov
Manishearth Aug 26, 2021
cf5e362
Rollup merge of #88216 - kornelski:from_layout_err, r=kennytm
Manishearth Aug 26, 2021
1e94fe1
Rollup merge of #88270 - lqd:hrtb-type-ascription, r=nikomatsakis
Manishearth Aug 26, 2021
dfca7b3
Rollup merge of #88289 - durin42:llvm-14-attrs, r=nikic
Manishearth Aug 26, 2021
c418a48
Rollup merge of #88320 - sexxi-goose:issue-88103, r=nikomatsakis
Manishearth Aug 26, 2021
0f7dc5d
Rollup merge of #88332 - spastorino:argument-types-tait-test, r=oli-obk
Manishearth Aug 26, 2021
e760740
Rollup merge of #88340 - thomcc:c_size_t, r=joshtriplett
Manishearth Aug 26, 2021
cb95e36
Rollup merge of #88346 - spastorino:revert-type-of-a-let2, r=jackh726
Manishearth Aug 26, 2021
af54936
Rollup merge of #88348 - spastorino:field-types-tait-test, r=oli-obk
Manishearth 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
23 changes: 9 additions & 14 deletions compiler/rustc_llvm/llvm-wrapper/RustWrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -270,34 +270,30 @@ extern "C" void LLVMRustAddFunctionAttribute(LLVMValueRef Fn, unsigned Index,
LLVMRustAttribute RustAttr) {
Function *A = unwrap<Function>(Fn);
Attribute Attr = Attribute::get(A->getContext(), fromRust(RustAttr));
AttrBuilder B(Attr);
A->addAttributes(Index, B);
A->addAttribute(Index, Attr);
}

extern "C" void LLVMRustAddAlignmentAttr(LLVMValueRef Fn,
unsigned Index,
uint32_t Bytes) {
Function *A = unwrap<Function>(Fn);
AttrBuilder B;
B.addAlignmentAttr(Bytes);
A->addAttributes(Index, B);
A->addAttribute(Index, Attribute::getWithAlignment(
A->getContext(), llvm::Align(Bytes)));
}

extern "C" void LLVMRustAddDereferenceableAttr(LLVMValueRef Fn, unsigned Index,
uint64_t Bytes) {
Function *A = unwrap<Function>(Fn);
AttrBuilder B;
B.addDereferenceableAttr(Bytes);
A->addAttributes(Index, B);
A->addAttribute(Index, Attribute::getWithDereferenceableBytes(A->getContext(),
Bytes));
}

extern "C" void LLVMRustAddDereferenceableOrNullAttr(LLVMValueRef Fn,
unsigned Index,
uint64_t Bytes) {
Function *A = unwrap<Function>(Fn);
AttrBuilder B;
B.addDereferenceableOrNullAttr(Bytes);
A->addAttributes(Index, B);
A->addAttribute(Index, Attribute::getWithDereferenceableOrNullBytes(
A->getContext(), Bytes));
}

extern "C" void LLVMRustAddByValAttr(LLVMValueRef Fn, unsigned Index,
Expand All @@ -323,9 +319,8 @@ extern "C" void LLVMRustAddFunctionAttrStringValue(LLVMValueRef Fn,
const char *Name,
const char *Value) {
Function *F = unwrap<Function>(Fn);
AttrBuilder B;
B.addAttribute(Name, Value);
F->addAttributes(Index, B);
F->addAttribute(Index, Attribute::get(
F->getContext(), StringRef(Name), StringRef(Value)));
}

extern "C" void LLVMRustRemoveFunctionAttributes(LLVMValueRef Fn,
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
63 changes: 54 additions & 9 deletions compiler/rustc_mir_build/src/build/matches/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ use rustc_middle::mir::*;
use rustc_middle::thir::{self, *};
use rustc_middle::ty::{self, CanonicalUserTypeAnnotation, Ty};
use rustc_span::symbol::Symbol;
use rustc_span::Span;
use rustc_span::{BytePos, Pos, Span};
use rustc_target::abi::VariantIdx;
use smallvec::{smallvec, SmallVec};

Expand Down Expand Up @@ -143,8 +143,15 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
let mut candidates =
arm_candidates.iter_mut().map(|(_, candidate)| candidate).collect::<Vec<_>>();

let fake_borrow_temps =
self.lower_match_tree(block, scrutinee_span, match_has_guard, &mut candidates);
let match_start_span = span.shrink_to_lo().to(scrutinee.span);

let fake_borrow_temps = self.lower_match_tree(
block,
scrutinee_span,
match_start_span,
match_has_guard,
&mut candidates,
);

self.lower_match_arms(
destination,
Expand Down Expand Up @@ -224,6 +231,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
&mut self,
block: BasicBlock,
scrutinee_span: Span,
match_start_span: Span,
match_has_guard: bool,
candidates: &mut [&mut Candidate<'pat, 'tcx>],
) -> Vec<(Place<'tcx>, Local)> {
Expand All @@ -236,7 +244,14 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {

// This will generate code to test scrutinee_place and
// branch to the appropriate arm block
self.match_candidates(scrutinee_span, block, &mut otherwise, candidates, &mut fake_borrows);
self.match_candidates(
match_start_span,
scrutinee_span,
block,
&mut otherwise,
candidates,
&mut fake_borrows,
);

if let Some(otherwise_block) = otherwise {
// See the doc comment on `match_candidates` for why we may have an
Expand Down Expand Up @@ -339,8 +354,14 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
// all the arm blocks will rejoin here
let end_block = self.cfg.start_new_block();

let end_brace = self.source_info(
outer_source_info.span.with_lo(outer_source_info.span.hi() - BytePos::from_usize(1)),
);
for arm_block in arm_end_blocks {
self.cfg.goto(unpack!(arm_block), outer_source_info, end_block);
let block = &self.cfg.basic_blocks[arm_block.0];
let last_location = block.statements.last().map(|s| s.source_info);

self.cfg.goto(unpack!(arm_block), last_location.unwrap_or(end_brace), end_block);
}

self.source_scope = outer_source_info.scope;
Expand Down Expand Up @@ -533,8 +554,13 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
set_match_place: bool,
) -> BlockAnd<()> {
let mut candidate = Candidate::new(initializer.clone(), &irrefutable_pat, false);
let fake_borrow_temps =
self.lower_match_tree(block, irrefutable_pat.span, false, &mut [&mut candidate]);
let fake_borrow_temps = self.lower_match_tree(
block,
irrefutable_pat.span,
irrefutable_pat.span,
false,
&mut [&mut candidate],
);
// For matches and function arguments, the place that is being matched
// can be set when creating the variables. But the place for
// let PATTERN = ... might not even exist until we do the assignment.
Expand Down Expand Up @@ -993,6 +1019,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
fn match_candidates<'pat>(
&mut self,
span: Span,
scrutinee_span: Span,
start_block: BasicBlock,
otherwise_block: &mut Option<BasicBlock>,
candidates: &mut [&mut Candidate<'pat, 'tcx>],
Expand Down Expand Up @@ -1022,6 +1049,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
}
self.match_simplified_candidates(
span,
scrutinee_span,
start_block,
otherwise_block,
&mut *new_candidates,
Expand All @@ -1030,6 +1058,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
} else {
self.match_simplified_candidates(
span,
scrutinee_span,
start_block,
otherwise_block,
candidates,
Expand All @@ -1042,6 +1071,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
fn match_simplified_candidates(
&mut self,
span: Span,
scrutinee_span: Span,
start_block: BasicBlock,
otherwise_block: &mut Option<BasicBlock>,
candidates: &mut [&mut Candidate<'_, 'tcx>],
Expand Down Expand Up @@ -1087,6 +1117,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
// Test for the remaining candidates.
self.test_candidates_with_or(
span,
scrutinee_span,
unmatched_candidates,
block,
otherwise_block,
Expand Down Expand Up @@ -1257,6 +1288,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
fn test_candidates_with_or(
&mut self,
span: Span,
scrutinee_span: Span,
candidates: &mut [&mut Candidate<'_, 'tcx>],
block: BasicBlock,
otherwise_block: &mut Option<BasicBlock>,
Expand All @@ -1269,7 +1301,14 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
match *first_candidate.match_pairs[0].pattern.kind {
PatKind::Or { .. } => (),
_ => {
self.test_candidates(span, candidates, block, otherwise_block, fake_borrows);
self.test_candidates(
span,
scrutinee_span,
candidates,
block,
otherwise_block,
fake_borrows,
);
return;
}
}
Expand Down Expand Up @@ -1302,6 +1341,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {

self.match_candidates(
span,
scrutinee_span,
remainder_start,
otherwise_block,
remaining_candidates,
Expand Down Expand Up @@ -1330,6 +1370,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
otherwise
};
self.match_candidates(
or_span,
or_span,
candidate.pre_binding_block.unwrap(),
otherwise,
Expand Down Expand Up @@ -1497,6 +1538,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
fn test_candidates<'pat, 'b, 'c>(
&mut self,
span: Span,
scrutinee_span: Span,
mut candidates: &'b mut [&'c mut Candidate<'pat, 'tcx>],
block: BasicBlock,
otherwise_block: &mut Option<BasicBlock>,
Expand Down Expand Up @@ -1591,6 +1633,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
let candidate_start = this.cfg.start_new_block();
this.match_candidates(
span,
scrutinee_span,
candidate_start,
remainder_start,
&mut *candidates,
Expand All @@ -1607,6 +1650,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
let remainder_start = remainder_start.unwrap_or_else(|| this.cfg.start_new_block());
this.match_candidates(
span,
scrutinee_span,
remainder_start,
otherwise_block,
candidates,
Expand All @@ -1617,7 +1661,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
target_blocks
};

self.perform_test(block, match_place, &test, make_target_blocks);
self.perform_test(span, scrutinee_span, block, match_place, &test, make_target_blocks);
}

/// Determine the fake borrows that are needed from a set of places that
Expand Down Expand Up @@ -1713,6 +1757,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
let fake_borrow_temps = self.lower_match_tree(
block,
pat.span,
pat.span,
false,
&mut [&mut guard_candidate, &mut otherwise_candidate],
);
Expand Down
Loading