Skip to content

Commit d5cd320

Browse files
committed
Auto merge of rust-lang#88371 - Manishearth:rollup-pkkjsme, r=Manishearth
Rollup of 11 pull requests Successful merges: - rust-lang#87832 (Fix debugger stepping behavior with `match` expressions) - rust-lang#88123 (Make spans for tuple patterns in E0023 more precise) - rust-lang#88215 (Reland rust-lang#83738: "rustdoc: Don't load all extern crates unconditionally") - rust-lang#88216 (Don't stabilize creation of TryReserveError instances) - rust-lang#88270 (Handle type ascription type ops in NLL HRTB diagnostics) - rust-lang#88289 (Fixes for LLVM change 0f45c16) - rust-lang#88320 (type_implements_trait consider obligation failure on overflow) - rust-lang#88332 (Add argument types tait tests) - rust-lang#88340 (Add `c_size_t` and `c_ssize_t` to `std::os::raw`.) - rust-lang#88346 (Revert "Add type of a let tait test impl trait straight in let") - rust-lang#88348 (Add field types tait tests) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents 517c28e + af54936 commit d5cd320

File tree

140 files changed

+2389
-710
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

140 files changed

+2389
-710
lines changed

compiler/rustc_hir/src/hir.rs

+33-2
Original file line numberDiff line numberDiff line change
@@ -3183,6 +3183,20 @@ pub enum Node<'hir> {
31833183
}
31843184

31853185
impl<'hir> Node<'hir> {
3186+
/// Get the identifier of this `Node`, if applicable.
3187+
///
3188+
/// # Edge cases
3189+
///
3190+
/// Calling `.ident()` on a [`Node::Ctor`] will return `None`
3191+
/// because `Ctor`s do not have identifiers themselves.
3192+
/// Instead, call `.ident()` on the parent struct/variant, like so:
3193+
///
3194+
/// ```ignore (illustrative)
3195+
/// ctor
3196+
/// .ctor_hir_id()
3197+
/// .and_then(|ctor_id| tcx.hir().find(tcx.hir().get_parent_node(ctor_id)))
3198+
/// .and_then(|parent| parent.ident())
3199+
/// ```
31863200
pub fn ident(&self) -> Option<Ident> {
31873201
match self {
31883202
Node::TraitItem(TraitItem { ident, .. })
@@ -3191,8 +3205,25 @@ impl<'hir> Node<'hir> {
31913205
| Node::Field(FieldDef { ident, .. })
31923206
| Node::Variant(Variant { ident, .. })
31933207
| Node::MacroDef(MacroDef { ident, .. })
3194-
| Node::Item(Item { ident, .. }) => Some(*ident),
3195-
_ => None,
3208+
| Node::Item(Item { ident, .. })
3209+
| Node::PathSegment(PathSegment { ident, .. }) => Some(*ident),
3210+
Node::Lifetime(lt) => Some(lt.name.ident()),
3211+
Node::GenericParam(p) => Some(p.name.ident()),
3212+
Node::Param(..)
3213+
| Node::AnonConst(..)
3214+
| Node::Expr(..)
3215+
| Node::Stmt(..)
3216+
| Node::Block(..)
3217+
| Node::Ctor(..)
3218+
| Node::Pat(..)
3219+
| Node::Binding(..)
3220+
| Node::Arm(..)
3221+
| Node::Local(..)
3222+
| Node::Visibility(..)
3223+
| Node::Crate(..)
3224+
| Node::Ty(..)
3225+
| Node::TraitRef(..)
3226+
| Node::Infer(..) => None,
31963227
}
31973228
}
31983229

compiler/rustc_llvm/llvm-wrapper/RustWrapper.cpp

+9-14
Original file line numberDiff line numberDiff line change
@@ -270,34 +270,30 @@ extern "C" void LLVMRustAddFunctionAttribute(LLVMValueRef Fn, unsigned Index,
270270
LLVMRustAttribute RustAttr) {
271271
Function *A = unwrap<Function>(Fn);
272272
Attribute Attr = Attribute::get(A->getContext(), fromRust(RustAttr));
273-
AttrBuilder B(Attr);
274-
A->addAttributes(Index, B);
273+
A->addAttribute(Index, Attr);
275274
}
276275

277276
extern "C" void LLVMRustAddAlignmentAttr(LLVMValueRef Fn,
278277
unsigned Index,
279278
uint32_t Bytes) {
280279
Function *A = unwrap<Function>(Fn);
281-
AttrBuilder B;
282-
B.addAlignmentAttr(Bytes);
283-
A->addAttributes(Index, B);
280+
A->addAttribute(Index, Attribute::getWithAlignment(
281+
A->getContext(), llvm::Align(Bytes)));
284282
}
285283

286284
extern "C" void LLVMRustAddDereferenceableAttr(LLVMValueRef Fn, unsigned Index,
287285
uint64_t Bytes) {
288286
Function *A = unwrap<Function>(Fn);
289-
AttrBuilder B;
290-
B.addDereferenceableAttr(Bytes);
291-
A->addAttributes(Index, B);
287+
A->addAttribute(Index, Attribute::getWithDereferenceableBytes(A->getContext(),
288+
Bytes));
292289
}
293290

294291
extern "C" void LLVMRustAddDereferenceableOrNullAttr(LLVMValueRef Fn,
295292
unsigned Index,
296293
uint64_t Bytes) {
297294
Function *A = unwrap<Function>(Fn);
298-
AttrBuilder B;
299-
B.addDereferenceableOrNullAttr(Bytes);
300-
A->addAttributes(Index, B);
295+
A->addAttribute(Index, Attribute::getWithDereferenceableOrNullBytes(
296+
A->getContext(), Bytes));
301297
}
302298

303299
extern "C" void LLVMRustAddByValAttr(LLVMValueRef Fn, unsigned Index,
@@ -323,9 +319,8 @@ extern "C" void LLVMRustAddFunctionAttrStringValue(LLVMValueRef Fn,
323319
const char *Name,
324320
const char *Value) {
325321
Function *F = unwrap<Function>(Fn);
326-
AttrBuilder B;
327-
B.addAttribute(Name, Value);
328-
F->addAttributes(Index, B);
322+
F->addAttribute(Index, Attribute::get(
323+
F->getContext(), StringRef(Name), StringRef(Value)));
329324
}
330325

331326
extern "C" void LLVMRustRemoveFunctionAttributes(LLVMValueRef Fn,

compiler/rustc_mir/src/borrow_check/diagnostics/bound_region_errors.rs

+37-5
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use rustc_middle::ty::{self, Ty, TyCtxt, TypeFoldable};
99
use rustc_span::Span;
1010
use rustc_trait_selection::traits::query::type_op;
1111
use rustc_trait_selection::traits::{SelectionContext, TraitEngineExt as _};
12-
use rustc_traits::type_op_prove_predicate_with_span;
12+
use rustc_traits::{type_op_ascribe_user_type_with_span, type_op_prove_predicate_with_span};
1313

1414
use std::fmt;
1515
use std::rc::Rc;
@@ -104,10 +104,11 @@ impl<'tcx, T: Copy + fmt::Display + TypeFoldable<'tcx> + 'tcx> ToUniverseInfo<'t
104104
impl<'tcx> ToUniverseInfo<'tcx>
105105
for Canonical<'tcx, ty::ParamEnvAnd<'tcx, type_op::AscribeUserType<'tcx>>>
106106
{
107-
fn to_universe_info(self, _base_universe: ty::UniverseIndex) -> UniverseInfo<'tcx> {
108-
// Ascribe user type isn't usually called on types that have different
109-
// bound regions.
110-
UniverseInfo::other()
107+
fn to_universe_info(self, base_universe: ty::UniverseIndex) -> UniverseInfo<'tcx> {
108+
UniverseInfo(UniverseInfoInner::TypeOp(Rc::new(AscribeUserTypeQuery {
109+
canonical_query: self,
110+
base_universe,
111+
})))
111112
}
112113
}
113114

@@ -267,6 +268,37 @@ where
267268
}
268269
}
269270

271+
struct AscribeUserTypeQuery<'tcx> {
272+
canonical_query: Canonical<'tcx, ty::ParamEnvAnd<'tcx, type_op::AscribeUserType<'tcx>>>,
273+
base_universe: ty::UniverseIndex,
274+
}
275+
276+
impl TypeOpInfo<'tcx> for AscribeUserTypeQuery<'tcx> {
277+
fn fallback_error(&self, tcx: TyCtxt<'tcx>, span: Span) -> DiagnosticBuilder<'tcx> {
278+
// FIXME: This error message isn't great, but it doesn't show up in the existing UI tests,
279+
// and is only the fallback when the nice error fails. Consider improving this some more.
280+
tcx.sess.struct_span_err(span, "higher-ranked lifetime error")
281+
}
282+
283+
fn base_universe(&self) -> ty::UniverseIndex {
284+
self.base_universe
285+
}
286+
287+
fn nice_error(
288+
&self,
289+
tcx: TyCtxt<'tcx>,
290+
span: Span,
291+
placeholder_region: ty::Region<'tcx>,
292+
error_region: Option<ty::Region<'tcx>>,
293+
) -> Option<DiagnosticBuilder<'tcx>> {
294+
tcx.infer_ctxt().enter_with_canonical(span, &self.canonical_query, |ref infcx, key, _| {
295+
let mut fulfill_cx = <dyn TraitEngine<'_>>::new(tcx);
296+
type_op_ascribe_user_type_with_span(infcx, &mut *fulfill_cx, key, Some(span)).ok()?;
297+
try_extract_error_from_fulfill_cx(fulfill_cx, infcx, placeholder_region, error_region)
298+
})
299+
}
300+
}
301+
270302
fn try_extract_error_from_fulfill_cx<'tcx>(
271303
mut fulfill_cx: Box<dyn TraitEngine<'tcx> + 'tcx>,
272304
infcx: &InferCtxt<'_, 'tcx>,

compiler/rustc_mir_build/src/build/matches/mod.rs

+54-9
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ use rustc_middle::mir::*;
2121
use rustc_middle::thir::{self, *};
2222
use rustc_middle::ty::{self, CanonicalUserTypeAnnotation, Ty};
2323
use rustc_span::symbol::Symbol;
24-
use rustc_span::Span;
24+
use rustc_span::{BytePos, Pos, Span};
2525
use rustc_target::abi::VariantIdx;
2626
use smallvec::{smallvec, SmallVec};
2727

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

146-
let fake_borrow_temps =
147-
self.lower_match_tree(block, scrutinee_span, match_has_guard, &mut candidates);
146+
let match_start_span = span.shrink_to_lo().to(scrutinee.span);
147+
148+
let fake_borrow_temps = self.lower_match_tree(
149+
block,
150+
scrutinee_span,
151+
match_start_span,
152+
match_has_guard,
153+
&mut candidates,
154+
);
148155

149156
self.lower_match_arms(
150157
destination,
@@ -224,6 +231,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
224231
&mut self,
225232
block: BasicBlock,
226233
scrutinee_span: Span,
234+
match_start_span: Span,
227235
match_has_guard: bool,
228236
candidates: &mut [&mut Candidate<'pat, 'tcx>],
229237
) -> Vec<(Place<'tcx>, Local)> {
@@ -236,7 +244,14 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
236244

237245
// This will generate code to test scrutinee_place and
238246
// branch to the appropriate arm block
239-
self.match_candidates(scrutinee_span, block, &mut otherwise, candidates, &mut fake_borrows);
247+
self.match_candidates(
248+
match_start_span,
249+
scrutinee_span,
250+
block,
251+
&mut otherwise,
252+
candidates,
253+
&mut fake_borrows,
254+
);
240255

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

357+
let end_brace = self.source_info(
358+
outer_source_info.span.with_lo(outer_source_info.span.hi() - BytePos::from_usize(1)),
359+
);
342360
for arm_block in arm_end_blocks {
343-
self.cfg.goto(unpack!(arm_block), outer_source_info, end_block);
361+
let block = &self.cfg.basic_blocks[arm_block.0];
362+
let last_location = block.statements.last().map(|s| s.source_info);
363+
364+
self.cfg.goto(unpack!(arm_block), last_location.unwrap_or(end_brace), end_block);
344365
}
345366

346367
self.source_scope = outer_source_info.scope;
@@ -533,8 +554,13 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
533554
set_match_place: bool,
534555
) -> BlockAnd<()> {
535556
let mut candidate = Candidate::new(initializer.clone(), &irrefutable_pat, false);
536-
let fake_borrow_temps =
537-
self.lower_match_tree(block, irrefutable_pat.span, false, &mut [&mut candidate]);
557+
let fake_borrow_temps = self.lower_match_tree(
558+
block,
559+
irrefutable_pat.span,
560+
irrefutable_pat.span,
561+
false,
562+
&mut [&mut candidate],
563+
);
538564
// For matches and function arguments, the place that is being matched
539565
// can be set when creating the variables. But the place for
540566
// let PATTERN = ... might not even exist until we do the assignment.
@@ -993,6 +1019,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
9931019
fn match_candidates<'pat>(
9941020
&mut self,
9951021
span: Span,
1022+
scrutinee_span: Span,
9961023
start_block: BasicBlock,
9971024
otherwise_block: &mut Option<BasicBlock>,
9981025
candidates: &mut [&mut Candidate<'pat, 'tcx>],
@@ -1022,6 +1049,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
10221049
}
10231050
self.match_simplified_candidates(
10241051
span,
1052+
scrutinee_span,
10251053
start_block,
10261054
otherwise_block,
10271055
&mut *new_candidates,
@@ -1030,6 +1058,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
10301058
} else {
10311059
self.match_simplified_candidates(
10321060
span,
1061+
scrutinee_span,
10331062
start_block,
10341063
otherwise_block,
10351064
candidates,
@@ -1042,6 +1071,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
10421071
fn match_simplified_candidates(
10431072
&mut self,
10441073
span: Span,
1074+
scrutinee_span: Span,
10451075
start_block: BasicBlock,
10461076
otherwise_block: &mut Option<BasicBlock>,
10471077
candidates: &mut [&mut Candidate<'_, 'tcx>],
@@ -1087,6 +1117,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
10871117
// Test for the remaining candidates.
10881118
self.test_candidates_with_or(
10891119
span,
1120+
scrutinee_span,
10901121
unmatched_candidates,
10911122
block,
10921123
otherwise_block,
@@ -1257,6 +1288,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
12571288
fn test_candidates_with_or(
12581289
&mut self,
12591290
span: Span,
1291+
scrutinee_span: Span,
12601292
candidates: &mut [&mut Candidate<'_, 'tcx>],
12611293
block: BasicBlock,
12621294
otherwise_block: &mut Option<BasicBlock>,
@@ -1269,7 +1301,14 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
12691301
match *first_candidate.match_pairs[0].pattern.kind {
12701302
PatKind::Or { .. } => (),
12711303
_ => {
1272-
self.test_candidates(span, candidates, block, otherwise_block, fake_borrows);
1304+
self.test_candidates(
1305+
span,
1306+
scrutinee_span,
1307+
candidates,
1308+
block,
1309+
otherwise_block,
1310+
fake_borrows,
1311+
);
12731312
return;
12741313
}
12751314
}
@@ -1302,6 +1341,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
13021341

13031342
self.match_candidates(
13041343
span,
1344+
scrutinee_span,
13051345
remainder_start,
13061346
otherwise_block,
13071347
remaining_candidates,
@@ -1330,6 +1370,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
13301370
otherwise
13311371
};
13321372
self.match_candidates(
1373+
or_span,
13331374
or_span,
13341375
candidate.pre_binding_block.unwrap(),
13351376
otherwise,
@@ -1497,6 +1538,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
14971538
fn test_candidates<'pat, 'b, 'c>(
14981539
&mut self,
14991540
span: Span,
1541+
scrutinee_span: Span,
15001542
mut candidates: &'b mut [&'c mut Candidate<'pat, 'tcx>],
15011543
block: BasicBlock,
15021544
otherwise_block: &mut Option<BasicBlock>,
@@ -1591,6 +1633,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
15911633
let candidate_start = this.cfg.start_new_block();
15921634
this.match_candidates(
15931635
span,
1636+
scrutinee_span,
15941637
candidate_start,
15951638
remainder_start,
15961639
&mut *candidates,
@@ -1607,6 +1650,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
16071650
let remainder_start = remainder_start.unwrap_or_else(|| this.cfg.start_new_block());
16081651
this.match_candidates(
16091652
span,
1653+
scrutinee_span,
16101654
remainder_start,
16111655
otherwise_block,
16121656
candidates,
@@ -1617,7 +1661,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
16171661
target_blocks
16181662
};
16191663

1620-
self.perform_test(block, match_place, &test, make_target_blocks);
1664+
self.perform_test(span, scrutinee_span, block, match_place, &test, make_target_blocks);
16211665
}
16221666

16231667
/// Determine the fake borrows that are needed from a set of places that
@@ -1713,6 +1757,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
17131757
let fake_borrow_temps = self.lower_match_tree(
17141758
block,
17151759
pat.span,
1760+
pat.span,
17161761
false,
17171762
&mut [&mut guard_candidate, &mut otherwise_candidate],
17181763
);

0 commit comments

Comments
 (0)