Skip to content

Commit 119307a

Browse files
committed
Auto merge of #67764 - Centril:rollup-ycbq3os, r=Centril
Rollup of 6 pull requests Successful merges: - #67574 (Extract `rustc_ast_lowering` crate from `rustc`) - #67685 (Constify Result) - #67702 (Add symbol normalization for proc_macro_server.) - #67730 (Cleanup pattern type checking, fix diagnostics bugs (+ improvements)) - #67744 (parser: reduce diversity in error handling mechanisms) - #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

+18
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

+1
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

+6-3
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

+1-2
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

+11-7
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

-1
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

+1-1
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

+1-1
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

+9-5
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

+4-4
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 }))

src/librustc_ast_lowering/Cargo.toml

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
[package]
2+
authors = ["The Rust Project Developers"]
3+
name = "rustc_ast_lowering"
4+
version = "0.0.0"
5+
edition = "2018"
6+
7+
[lib]
8+
name = "rustc_ast_lowering"
9+
path = "lib.rs"
10+
doctest = false
11+
12+
[dependencies]
13+
log = { version = "0.4", features = ["release_max_level_info", "std"] }
14+
rustc = { path = "../librustc" }
15+
rustc_target = { path = "../librustc_target" }
16+
rustc_data_structures = { path = "../librustc_data_structures" }
17+
rustc_index = { path = "../librustc_index" }
18+
rustc_span = { path = "../librustc_span" }
19+
rustc_error_codes = { path = "../librustc_error_codes" }
20+
rustc_errors = { path = "../librustc_errors" }
21+
syntax = { path = "../libsyntax" }
22+
smallvec = { version = "1.0", features = ["union", "may_dangle"] }

src/librustc/hir/lowering/expr.rs renamed to src/librustc_ast_lowering/expr.rs

+14-28
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
use super::{ImplTraitContext, LoweringContext, ParamMode, ParenthesizedGenericArgs};
2-
use crate::hir;
3-
use crate::hir::def::Res;
42

3+
use rustc::bug;
4+
use rustc::hir;
5+
use rustc::hir::def::Res;
56
use rustc_data_structures::thin_vec::ThinVec;
6-
7+
use rustc_error_codes::*;
8+
use rustc_span::source_map::{respan, DesugaringKind, Span, Spanned};
9+
use rustc_span::symbol::{sym, Symbol};
710
use syntax::ast::*;
811
use syntax::attr;
912
use syntax::ptr::P as AstP;
10-
use syntax::source_map::{respan, DesugaringKind, Span, Spanned};
11-
use syntax::symbol::{sym, Symbol};
12-
13-
use rustc_error_codes::*;
13+
use syntax::{span_err, struct_span_err};
1414

1515
impl<'hir> LoweringContext<'_, 'hir> {
1616
fn lower_exprs(&mut self, exprs: &[AstP<Expr>]) -> &'hir [hir::Expr<'hir>] {
@@ -82,11 +82,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
8282
this.lower_expr_while_in_loop_scope(e.span, cond, body, opt_label)
8383
}),
8484
ExprKind::Loop(ref body, opt_label) => self.with_loop_scope(e.id, |this| {
85-
hir::ExprKind::Loop(
86-
this.lower_block(body, false),
87-
this.lower_label(opt_label),
88-
hir::LoopSource::Loop,
89-
)
85+
hir::ExprKind::Loop(this.lower_block(body, false), opt_label, hir::LoopSource::Loop)
9086
}),
9187
ExprKind::TryBlock(ref body) => self.lower_expr_try_block(body),
9288
ExprKind::Match(ref expr, ref arms) => hir::ExprKind::Match(
@@ -123,10 +119,9 @@ impl<'hir> LoweringContext<'_, 'hir> {
123119
self.lower_expr_closure(capture_clause, movability, decl, body, fn_decl_span)
124120
}
125121
}
126-
ExprKind::Block(ref blk, opt_label) => hir::ExprKind::Block(
127-
self.lower_block(blk, opt_label.is_some()),
128-
self.lower_label(opt_label),
129-
),
122+
ExprKind::Block(ref blk, opt_label) => {
123+
hir::ExprKind::Block(self.lower_block(blk, opt_label.is_some()), opt_label)
124+
}
130125
ExprKind::Assign(ref el, ref er, span) => {
131126
hir::ExprKind::Assign(self.lower_expr(el), self.lower_expr(er), span)
132127
}
@@ -407,11 +402,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
407402
);
408403

409404
// `[opt_ident]: loop { ... }`
410-
hir::ExprKind::Loop(
411-
self.block_expr(self.arena.alloc(match_expr)),
412-
self.lower_label(opt_label),
413-
source,
414-
)
405+
hir::ExprKind::Loop(self.block_expr(self.arena.alloc(match_expr)), opt_label, source)
415406
}
416407

417408
/// Desugar `try { <stmts>; <expr> }` into `{ <stmts>; ::std::ops::Try::from_ok(<expr>) }`,
@@ -836,10 +827,6 @@ impl<'hir> LoweringContext<'_, 'hir> {
836827
}
837828
}
838829

839-
fn lower_label(&mut self, label: Option<Label>) -> Option<hir::Label> {
840-
label.map(|label| hir::Label { ident: label.ident })
841-
}
842-
843830
fn lower_loop_destination(&mut self, destination: Option<(NodeId, Label)>) -> hir::Destination {
844831
let target_id = match destination {
845832
Some((id, _)) => {
@@ -857,7 +844,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
857844
.unwrap_or(Err(hir::LoopIdError::OutsideLoopScope))
858845
.into(),
859846
};
860-
hir::Destination { label: self.lower_label(destination.map(|(_, label)| label)), target_id }
847+
hir::Destination { label: destination.map(|(_, label)| label), target_id }
861848
}
862849

863850
fn lower_jump_destination(&mut self, id: NodeId, opt_label: Option<Label>) -> hir::Destination {
@@ -1100,8 +1087,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
11001087
);
11011088

11021089
// `[opt_ident]: loop { ... }`
1103-
let kind =
1104-
hir::ExprKind::Loop(loop_block, self.lower_label(opt_label), hir::LoopSource::ForLoop);
1090+
let kind = hir::ExprKind::Loop(loop_block, opt_label, hir::LoopSource::ForLoop);
11051091
let loop_expr = self.arena.alloc(hir::Expr {
11061092
hir_id: self.lower_node_id(e.id),
11071093
kind,

src/librustc/hir/lowering/item.rs renamed to src/librustc_ast_lowering/item.rs

+18-21
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,25 @@
1-
use super::AnonymousLifetimeMode;
2-
use super::ImplTraitContext;
3-
use super::ImplTraitPosition;
4-
use super::ImplTraitTypeIdVisitor;
5-
use super::LoweringContext;
6-
use super::ParamMode;
7-
8-
use crate::arena::Arena;
9-
use crate::hir;
10-
use crate::hir::def::{DefKind, Res};
11-
use crate::hir::def_id::DefId;
12-
use crate::util::nodemap::NodeMap;
13-
1+
use super::{AnonymousLifetimeMode, LoweringContext, ParamMode};
2+
use super::{ImplTraitContext, ImplTraitPosition, ImplTraitTypeIdVisitor};
3+
4+
use rustc::arena::Arena;
5+
use rustc::bug;
6+
use rustc::hir;
7+
use rustc::hir::def::{DefKind, Res};
8+
use rustc::hir::def_id::DefId;
9+
use rustc::util::nodemap::NodeMap;
10+
use rustc_error_codes::*;
11+
use rustc_span::source_map::{respan, DesugaringKind};
12+
use rustc_span::symbol::{kw, sym};
13+
use rustc_span::Span;
1414
use rustc_target::spec::abi;
15-
16-
use smallvec::SmallVec;
17-
use std::collections::BTreeSet;
1815
use syntax::ast::*;
1916
use syntax::attr;
20-
use syntax::source_map::{respan, DesugaringKind};
21-
use syntax::symbol::{kw, sym};
17+
use syntax::struct_span_err;
2218
use syntax::visit::{self, Visitor};
23-
use syntax_pos::Span;
2419

25-
use rustc_error_codes::*;
20+
use log::debug;
21+
use smallvec::{smallvec, SmallVec};
22+
use std::collections::BTreeSet;
2623

2724
pub(super) struct ItemLowerer<'a, 'lowering, 'hir> {
2825
pub(super) lctx: &'a mut LoweringContext<'lowering, 'hir>,
@@ -1429,7 +1426,7 @@ pub(super) struct GenericsCtor<'hir> {
14291426
span: Span,
14301427
}
14311428

1432-
impl GenericsCtor<'hir> {
1429+
impl<'hir> GenericsCtor<'hir> {
14331430
pub(super) fn into_generics(self, arena: &'hir Arena<'hir>) -> hir::Generics<'hir> {
14341431
hir::Generics {
14351432
params: arena.alloc_from_iter(self.params),

0 commit comments

Comments
 (0)