Skip to content

Commit 14dbf18

Browse files
authored
Merge branch 'rust-lang:master' into mo-usefull-order
2 parents 7ef37f3 + 19387d3 commit 14dbf18

Some content is hidden

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

55 files changed

+2039
-828
lines changed

Cargo.lock

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/hir-def/src/body/lower.rs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1611,7 +1611,11 @@ impl ExprCollector<'_> {
16111611
}
16121612
},
16131613
),
1614-
None => FormatArgs { template: Default::default(), arguments: args.finish() },
1614+
None => FormatArgs {
1615+
template: Default::default(),
1616+
arguments: args.finish(),
1617+
orphans: Default::default(),
1618+
},
16151619
};
16161620

16171621
// Create a list of all _unique_ (argument, format trait) combinations.
@@ -1750,7 +1754,13 @@ impl ExprCollector<'_> {
17501754
});
17511755
let unsafe_arg_new = self.alloc_expr_desugared(Expr::Unsafe {
17521756
id: None,
1753-
statements: Box::default(),
1757+
// We collect the unused expressions here so that we still infer them instead of
1758+
// dropping them out of the expression tree
1759+
statements: fmt
1760+
.orphans
1761+
.into_iter()
1762+
.map(|expr| Statement::Expr { expr, has_semi: true })
1763+
.collect(),
17541764
tail: Some(unsafe_arg_new),
17551765
});
17561766

crates/hir-def/src/hir/format_args.rs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ use std::mem;
33

44
use hir_expand::name::Name;
55
use rustc_dependencies::parse_format as parse;
6+
use stdx::TupleExt;
67
use syntax::{
78
ast::{self, IsString},
89
SmolStr, TextRange, TextSize,
@@ -14,6 +15,7 @@ use crate::hir::ExprId;
1415
pub struct FormatArgs {
1516
pub template: Box<[FormatArgsPiece]>,
1617
pub arguments: FormatArguments,
18+
pub orphans: Vec<ExprId>,
1719
}
1820

1921
#[derive(Debug, Clone, PartialEq, Eq)]
@@ -196,7 +198,11 @@ pub(crate) fn parse(
196198
let is_source_literal = parser.is_source_literal;
197199
if !parser.errors.is_empty() {
198200
// FIXME: Diagnose
199-
return FormatArgs { template: Default::default(), arguments: args.finish() };
201+
return FormatArgs {
202+
template: Default::default(),
203+
arguments: args.finish(),
204+
orphans: vec![],
205+
};
200206
}
201207

202208
let to_span = |inner_span: parse::InnerSpan| {
@@ -419,7 +425,11 @@ pub(crate) fn parse(
419425
// FIXME: Diagnose
420426
}
421427

422-
FormatArgs { template: template.into_boxed_slice(), arguments: args.finish() }
428+
FormatArgs {
429+
template: template.into_boxed_slice(),
430+
arguments: args.finish(),
431+
orphans: unused.into_iter().map(TupleExt::head).collect(),
432+
}
423433
}
424434

425435
#[derive(Debug, Clone, PartialEq, Eq)]

crates/hir-def/src/item_tree/tests.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -370,3 +370,15 @@ struct S<#[cfg(never)] T>;
370370
"#]],
371371
)
372372
}
373+
374+
#[test]
375+
fn pub_self() {
376+
check(
377+
r#"
378+
pub(self) struct S;
379+
"#,
380+
expect![[r#"
381+
pub(self) struct S;
382+
"#]],
383+
)
384+
}

crates/hir-def/src/macro_expansion_tests/builtin_fn_macro.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -468,12 +468,12 @@ macro_rules! concat_bytes {}
468468
469469
fn main() { concat_bytes!(b'A', b"BC", [68, b'E', 70]); }
470470
"##,
471-
expect![[r##"
471+
expect![[r#"
472472
#[rustc_builtin_macro]
473473
macro_rules! concat_bytes {}
474474
475475
fn main() { [b'A', 66, 67, 68, b'E', 70]; }
476-
"##]],
476+
"#]],
477477
);
478478
}
479479

crates/hir-def/src/macro_expansion_tests/mbe/regression.rs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1004,3 +1004,29 @@ fn main() {
10041004
"##]],
10051005
);
10061006
}
1007+
1008+
#[test]
1009+
fn eager_concat_bytes_panic() {
1010+
check(
1011+
r#"
1012+
#[rustc_builtin_macro]
1013+
#[macro_export]
1014+
macro_rules! concat_bytes {}
1015+
1016+
fn main() {
1017+
let x = concat_bytes!(2);
1018+
}
1019+
1020+
"#,
1021+
expect![[r#"
1022+
#[rustc_builtin_macro]
1023+
#[macro_export]
1024+
macro_rules! concat_bytes {}
1025+
1026+
fn main() {
1027+
let x = /* error: unexpected token in input */[];
1028+
}
1029+
1030+
"#]],
1031+
);
1032+
}

crates/hir-def/src/nameres/path_resolution.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,8 @@ impl DefMap {
9696
let types = result.take_types()?;
9797
match types {
9898
ModuleDefId::ModuleId(m) => Visibility::Module(m),
99+
// error: visibility needs to refer to module
99100
_ => {
100-
// error: visibility needs to refer to module
101101
return None;
102102
}
103103
}

crates/hir-def/src/resolver.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -588,6 +588,14 @@ impl Resolver {
588588
_ => None,
589589
})
590590
}
591+
592+
pub fn impl_def(&self) -> Option<ImplId> {
593+
self.scopes().find_map(|scope| match scope {
594+
Scope::ImplDefScope(def) => Some(*def),
595+
_ => None,
596+
})
597+
}
598+
591599
/// `expr_id` is required to be an expression id that comes after the top level expression scope in the given resolver
592600
#[must_use]
593601
pub fn update_to_inner_scope(

crates/hir-def/src/visibility.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ impl RawVisibility {
7373
RawVisibility::Module(path)
7474
}
7575
ast::VisibilityKind::PubSelf => {
76-
let path = ModPath::from_kind(PathKind::Plain);
76+
let path = ModPath::from_kind(PathKind::Super(0));
7777
RawVisibility::Module(path)
7878
}
7979
ast::VisibilityKind::Pub => RawVisibility::Public,

crates/hir-expand/src/builtin_fn_macro.rs

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ use base_db::{
66
};
77
use cfg::CfgExpr;
88
use either::Either;
9+
use itertools::Itertools;
910
use mbe::{parse_exprs_with_sep, parse_to_token_tree};
1011
use syntax::{
1112
ast::{self, AstToken},
@@ -491,8 +492,25 @@ fn concat_bytes_expand(
491492
}
492493
}
493494
}
494-
let ident = tt::Ident { text: bytes.join(", ").into(), span };
495-
ExpandResult { value: quote!(span =>[#ident]), err }
495+
let value = tt::Subtree {
496+
delimiter: tt::Delimiter { open: span, close: span, kind: tt::DelimiterKind::Bracket },
497+
token_trees: {
498+
Itertools::intersperse_with(
499+
bytes.into_iter().map(|it| {
500+
tt::TokenTree::Leaf(tt::Leaf::Literal(tt::Literal { text: it.into(), span }))
501+
}),
502+
|| {
503+
tt::TokenTree::Leaf(tt::Leaf::Punct(tt::Punct {
504+
char: ',',
505+
spacing: tt::Spacing::Alone,
506+
span,
507+
}))
508+
},
509+
)
510+
.collect()
511+
},
512+
};
513+
ExpandResult { value, err }
496514
}
497515

498516
fn concat_bytes_expand_subtree(

0 commit comments

Comments
 (0)