Skip to content

Commit 119307a

Browse files
committed
Auto merge of rust-lang#67764 - Centril:rollup-ycbq3os, r=Centril
Rollup of 6 pull requests Successful merges: - rust-lang#67574 (Extract `rustc_ast_lowering` crate from `rustc`) - rust-lang#67685 (Constify Result) - rust-lang#67702 (Add symbol normalization for proc_macro_server.) - rust-lang#67730 (Cleanup pattern type checking, fix diagnostics bugs (+ improvements)) - rust-lang#67744 (parser: reduce diversity in error handling mechanisms) - rust-lang#67748 (Use function attribute "frame-pointer" instead of "no-frame-pointer-elim") Failed merges: r? @ghost
2 parents 769eb21 + 40579d1 commit 119307a

File tree

86 files changed

+731
-509
lines changed

Some content is hidden

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

86 files changed

+731
-509
lines changed

Cargo.lock

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3358,6 +3358,22 @@ dependencies = [
33583358
"core",
33593359
]
33603360

3361+
[[package]]
3362+
name = "rustc_ast_lowering"
3363+
version = "0.0.0"
3364+
dependencies = [
3365+
"log",
3366+
"rustc",
3367+
"rustc_data_structures",
3368+
"rustc_error_codes",
3369+
"rustc_errors",
3370+
"rustc_index",
3371+
"rustc_span",
3372+
"rustc_target",
3373+
"smallvec 1.0.0",
3374+
"syntax",
3375+
]
3376+
33613377
[[package]]
33623378
name = "rustc_builtin_macros"
33633379
version = "0.0.0"
@@ -3578,6 +3594,7 @@ dependencies = [
35783594
"once_cell",
35793595
"rustc",
35803596
"rustc-rayon",
3597+
"rustc_ast_lowering",
35813598
"rustc_builtin_macros",
35823599
"rustc_codegen_llvm",
35833600
"rustc_codegen_ssa",
@@ -3783,6 +3800,7 @@ dependencies = [
37833800
"bitflags",
37843801
"log",
37853802
"rustc",
3803+
"rustc_ast_lowering",
37863804
"rustc_data_structures",
37873805
"rustc_error_codes",
37883806
"rustc_errors",

src/libcore/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@
7676
#![feature(const_fn_union)]
7777
#![feature(const_generics)]
7878
#![feature(const_ptr_offset_from)]
79+
#![feature(const_result)]
7980
#![feature(const_type_name)]
8081
#![feature(custom_inner_attributes)]
8182
#![feature(decl_macro)]

src/libcore/result.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -278,9 +278,10 @@ impl<T, E> Result<T, E> {
278278
/// assert_eq!(x.is_ok(), false);
279279
/// ```
280280
#[must_use = "if you intended to assert that this is ok, consider `.unwrap()` instead"]
281+
#[rustc_const_unstable(feature = "const_result", issue = "67520")]
281282
#[inline]
282283
#[stable(feature = "rust1", since = "1.0.0")]
283-
pub fn is_ok(&self) -> bool {
284+
pub const fn is_ok(&self) -> bool {
284285
match *self {
285286
Ok(_) => true,
286287
Err(_) => false,
@@ -303,9 +304,10 @@ impl<T, E> Result<T, E> {
303304
/// assert_eq!(x.is_err(), true);
304305
/// ```
305306
#[must_use = "if you intended to assert that this is err, consider `.unwrap_err()` instead"]
307+
#[rustc_const_unstable(feature = "const_result", issue = "67520")]
306308
#[inline]
307309
#[stable(feature = "rust1", since = "1.0.0")]
308-
pub fn is_err(&self) -> bool {
310+
pub const fn is_err(&self) -> bool {
309311
!self.is_ok()
310312
}
311313

@@ -446,8 +448,9 @@ impl<T, E> Result<T, E> {
446448
/// assert_eq!(x.as_ref(), Err(&"Error"));
447449
/// ```
448450
#[inline]
451+
#[rustc_const_unstable(feature = "const_result", issue = "67520")]
449452
#[stable(feature = "rust1", since = "1.0.0")]
450-
pub fn as_ref(&self) -> Result<&T, &E> {
453+
pub const fn as_ref(&self) -> Result<&T, &E> {
451454
match *self {
452455
Ok(ref x) => Ok(x),
453456
Err(ref x) => Err(x),

src/librustc/hir/mod.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ pub mod def;
3939
pub mod def_id;
4040
pub mod intravisit;
4141
pub mod itemlikevisit;
42-
pub mod lowering;
4342
pub mod map;
4443
pub mod pat_util;
4544
pub mod print;
@@ -599,7 +598,7 @@ pub enum SyntheticTyParamKind {
599598
pub struct WhereClause<'hir> {
600599
pub predicates: &'hir [WherePredicate<'hir>],
601600
// Only valid if predicates isn't empty.
602-
span: Span,
601+
pub span: Span,
603602
}
604603

605604
impl WhereClause<'_> {

src/librustc/infer/error_reporting/mod.rs

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -581,10 +581,11 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
581581
exp_found: Option<ty::error::ExpectedFound<Ty<'tcx>>>,
582582
) {
583583
match cause.code {
584-
ObligationCauseCode::MatchExpressionArmPattern { span, ty } => {
584+
ObligationCauseCode::Pattern { origin_expr: true, span: Some(span), root_ty } => {
585+
let ty = self.resolve_vars_if_possible(&root_ty);
585586
if ty.is_suggestable() {
586587
// don't show type `_`
587-
err.span_label(span, format!("this match expression has type `{}`", ty));
588+
err.span_label(span, format!("this expression has type `{}`", ty));
588589
}
589590
if let Some(ty::error::ExpectedFound { found, .. }) = exp_found {
590591
if ty.is_box() && ty.boxed_ty() == found {
@@ -599,11 +600,14 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
599600
}
600601
}
601602
}
603+
ObligationCauseCode::Pattern { origin_expr: false, span: Some(span), .. } => {
604+
err.span_label(span, "expected due to this");
605+
}
602606
ObligationCauseCode::MatchExpressionArm(box MatchExpressionArmCause {
603607
source,
604608
ref prior_arms,
605609
last_ty,
606-
discrim_hir_id,
610+
scrut_hir_id,
607611
..
608612
}) => match source {
609613
hir::MatchSource::IfLetDesugar { .. } => {
@@ -612,16 +616,16 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
612616
}
613617
hir::MatchSource::TryDesugar => {
614618
if let Some(ty::error::ExpectedFound { expected, .. }) = exp_found {
615-
let discrim_expr = self.tcx.hir().expect_expr(discrim_hir_id);
616-
let discrim_ty = if let hir::ExprKind::Call(_, args) = &discrim_expr.kind {
619+
let scrut_expr = self.tcx.hir().expect_expr(scrut_hir_id);
620+
let scrut_ty = if let hir::ExprKind::Call(_, args) = &scrut_expr.kind {
617621
let arg_expr = args.first().expect("try desugaring call w/out arg");
618622
self.in_progress_tables
619623
.and_then(|tables| tables.borrow().expr_ty_opt(arg_expr))
620624
} else {
621-
bug!("try desugaring w/out call expr as discriminant");
625+
bug!("try desugaring w/out call expr as scrutinee");
622626
};
623627

624-
match discrim_ty {
628+
match scrut_ty {
625629
Some(ty) if expected == ty => {
626630
let source_map = self.tcx.sess.source_map();
627631
err.span_suggestion(

src/librustc/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
2929
#![doc(html_root_url = "https://doc.rust-lang.org/nightly/")]
3030
#![feature(arbitrary_self_types)]
31-
#![feature(array_value_iter)]
3231
#![feature(bool_to_option)]
3332
#![feature(box_patterns)]
3433
#![feature(box_syntax)]

src/librustc/lint/builtin.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -523,7 +523,7 @@ pub enum BuiltinLintDiagnostics {
523523
DeprecatedMacro(Option<Symbol>, Span),
524524
}
525525

526-
pub(crate) fn add_elided_lifetime_in_path_suggestion(
526+
pub fn add_elided_lifetime_in_path_suggestion(
527527
sess: &Session,
528528
db: &mut DiagnosticBuilder<'_>,
529529
n: usize,

src/librustc/traits/error_reporting.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2580,7 +2580,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
25802580
match *cause_code {
25812581
ObligationCauseCode::ExprAssignable
25822582
| ObligationCauseCode::MatchExpressionArm { .. }
2583-
| ObligationCauseCode::MatchExpressionArmPattern { .. }
2583+
| ObligationCauseCode::Pattern { .. }
25842584
| ObligationCauseCode::IfExpression { .. }
25852585
| ObligationCauseCode::IfExpressionWithNoElse
25862586
| ObligationCauseCode::MainFunctionType

src/librustc/traits/mod.rs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -249,10 +249,14 @@ pub enum ObligationCauseCode<'tcx> {
249249
/// Computing common supertype in the arms of a match expression
250250
MatchExpressionArm(Box<MatchExpressionArmCause<'tcx>>),
251251

252-
/// Computing common supertype in the pattern guard for the arms of a match expression
253-
MatchExpressionArmPattern {
254-
span: Span,
255-
ty: Ty<'tcx>,
252+
/// Type error arising from type checking a pattern against an expected type.
253+
Pattern {
254+
/// The span of the scrutinee or type expression which caused the `root_ty` type.
255+
span: Option<Span>,
256+
/// The root expected type induced by a scrutinee or type expression.
257+
root_ty: Ty<'tcx>,
258+
/// Whether the `Span` came from an expression or a type expression.
259+
origin_expr: bool,
256260
},
257261

258262
/// Constants in patterns must have `Structural` type.
@@ -311,7 +315,7 @@ pub struct MatchExpressionArmCause<'tcx> {
311315
pub source: hir::MatchSource,
312316
pub prior_arms: Vec<Span>,
313317
pub last_ty: Ty<'tcx>,
314-
pub discrim_hir_id: hir::HirId,
318+
pub scrut_hir_id: hir::HirId,
315319
}
316320

317321
#[derive(Clone, Debug, PartialEq, Eq, Hash)]

src/librustc/traits/structural_impls.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -511,18 +511,18 @@ impl<'a, 'tcx> Lift<'tcx> for traits::ObligationCauseCode<'a> {
511511
source,
512512
ref prior_arms,
513513
last_ty,
514-
discrim_hir_id,
514+
scrut_hir_id,
515515
}) => tcx.lift(&last_ty).map(|last_ty| {
516516
super::MatchExpressionArm(box super::MatchExpressionArmCause {
517517
arm_span,
518518
source,
519519
prior_arms: prior_arms.clone(),
520520
last_ty,
521-
discrim_hir_id,
521+
scrut_hir_id,
522522
})
523523
}),
524-
super::MatchExpressionArmPattern { span, ty } => {
525-
tcx.lift(&ty).map(|ty| super::MatchExpressionArmPattern { span, ty })
524+
super::Pattern { span, root_ty, origin_expr } => {
525+
tcx.lift(&root_ty).map(|root_ty| super::Pattern { span, root_ty, origin_expr })
526526
}
527527
super::IfExpression(box super::IfExpressionCause { then, outer, semicolon }) => {
528528
Some(super::IfExpression(box super::IfExpressionCause { then, outer, semicolon }))

0 commit comments

Comments
 (0)