mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-28 01:34:21 +00:00
Some more minor cleanups
This commit is contained in:
parent
5edf7bddc6
commit
02a3a9438a
@ -4,7 +4,6 @@
|
||||
|
||||
mod input;
|
||||
mod change;
|
||||
// FIXME: Is this purely a test util mod? Consider #[cfg(test)] gating it.
|
||||
pub mod fixture;
|
||||
pub mod span;
|
||||
|
||||
|
@ -2,7 +2,6 @@ mod block;
|
||||
|
||||
use base_db::{fixture::WithFixture, SourceDatabase};
|
||||
use expect_test::{expect, Expect};
|
||||
use hir_expand::db::ExpandDatabase;
|
||||
|
||||
use crate::{test_db::TestDB, ModuleDefId};
|
||||
|
||||
@ -255,7 +254,6 @@ impl SsrError {
|
||||
}
|
||||
"##,
|
||||
);
|
||||
println!("{}", db.dump_syntax_contexts());
|
||||
|
||||
assert_eq!(db.body_with_source_map(def.into()).1.diagnostics(), &[]);
|
||||
expect![[r#"
|
||||
@ -288,3 +286,49 @@ impl SsrError {
|
||||
}"#]]
|
||||
.assert_eq(&body.pretty_print(&db, def))
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn regression_10300() {
|
||||
let (db, body, def) = lower(
|
||||
r#"
|
||||
//- minicore: concat, panic
|
||||
mod private {
|
||||
pub use core::concat;
|
||||
}
|
||||
|
||||
macro_rules! m {
|
||||
() => {
|
||||
panic!(concat!($crate::private::concat!("cc")));
|
||||
};
|
||||
}
|
||||
|
||||
fn f() {
|
||||
m!();
|
||||
}
|
||||
"#,
|
||||
);
|
||||
|
||||
let (_, source_map) = db.body_with_source_map(def.into());
|
||||
assert_eq!(source_map.diagnostics(), &[]);
|
||||
|
||||
for (_, def_map) in body.blocks(&db) {
|
||||
assert_eq!(def_map.diagnostics(), &[]);
|
||||
}
|
||||
|
||||
expect![[r#"
|
||||
fn f() {
|
||||
$crate::panicking::panic_fmt(
|
||||
builtin#lang(Arguments::new_v1_formatted)(
|
||||
&[
|
||||
"\"cc\"",
|
||||
],
|
||||
&[],
|
||||
&[],
|
||||
unsafe {
|
||||
builtin#lang(UnsafeArg::new)()
|
||||
},
|
||||
),
|
||||
);
|
||||
}"#]]
|
||||
.assert_eq(&body.pretty_print(&db, def))
|
||||
}
|
||||
|
@ -628,14 +628,13 @@ impl ExpansionInfo {
|
||||
span: SpanData,
|
||||
// FIXME: use this for range mapping, so that we can resolve inline format args
|
||||
_relative_token_offset: Option<TextSize>,
|
||||
// FIXME: ret ty should be wrapped in InMacroFile
|
||||
) -> Option<impl Iterator<Item = InFile<SyntaxToken>> + 'a> {
|
||||
) -> Option<impl Iterator<Item = InMacroFile<SyntaxToken>> + 'a> {
|
||||
let tokens = self
|
||||
.exp_map
|
||||
.ranges_with_span(span)
|
||||
.flat_map(move |range| self.expanded.value.covering_element(range).into_token());
|
||||
|
||||
Some(tokens.map(move |token| InFile::new(self.expanded.file_id.into(), token)))
|
||||
Some(tokens.map(move |token| InMacroFile::new(self.expanded.file_id, token)))
|
||||
}
|
||||
|
||||
/// Maps up the text range out of the expansion hierarchy back into the original file its from.
|
||||
|
@ -63,10 +63,10 @@ fn infer_macros_expanded() {
|
||||
}
|
||||
"#,
|
||||
expect![[r#"
|
||||
!0..21 '{Foo(v...2),])}': Foo
|
||||
!0..17 '{Foo(v...,2,])}': Foo
|
||||
!1..4 'Foo': Foo({unknown}) -> Foo
|
||||
!1..20 'Foo(ve...(2),])': Foo
|
||||
!5..19 'vec![(1),(2),]': {unknown}
|
||||
!1..16 'Foo(vec![1,2,])': Foo
|
||||
!5..15 'vec![1,2,]': {unknown}
|
||||
155..181 '{ ...,2); }': ()
|
||||
165..166 'x': Foo
|
||||
"#]],
|
||||
@ -96,10 +96,10 @@ fn infer_legacy_textual_scoped_macros_expanded() {
|
||||
}
|
||||
"#,
|
||||
expect![[r#"
|
||||
!0..21 '{Foo(v...2),])}': Foo
|
||||
!0..17 '{Foo(v...,2,])}': Foo
|
||||
!1..4 'Foo': Foo({unknown}) -> Foo
|
||||
!1..20 'Foo(ve...(2),])': Foo
|
||||
!5..19 'vec![(1),(2),]': {unknown}
|
||||
!1..16 'Foo(vec![1,2,])': Foo
|
||||
!5..15 'vec![1,2,]': {unknown}
|
||||
194..250 '{ ...,2); }': ()
|
||||
204..205 'x': Foo
|
||||
227..228 'y': {unknown}
|
||||
|
@ -557,11 +557,6 @@ impl<'db> SemanticsImpl<'db> {
|
||||
.span_at(token.text_range().start()),
|
||||
};
|
||||
|
||||
// fetch span information of token in real file, then use that look through expansions of
|
||||
// calls the token is in and afterwards recursively with the same span.
|
||||
// what about things where spans change? Due to being joined etc, that is we don't find the
|
||||
// exact span anymore?
|
||||
|
||||
let def_map = sa.resolver.def_map();
|
||||
let mut stack: SmallVec<[_; 4]> = smallvec![InFile::new(sa.file_id, token)];
|
||||
|
||||
@ -580,7 +575,7 @@ impl<'db> SemanticsImpl<'db> {
|
||||
let len = stack.len();
|
||||
|
||||
// requeue the tokens we got from mapping our current token down
|
||||
stack.extend(mapped_tokens);
|
||||
stack.extend(mapped_tokens.map(Into::into));
|
||||
// if the length changed we have found a mapping for the token
|
||||
(stack.len() != len).then_some(())
|
||||
};
|
||||
|
@ -340,8 +340,8 @@ fn main() {
|
||||
expect![[r#"
|
||||
match_ast!
|
||||
{
|
||||
if let Some(it) = ast::TraitDef::cast((container).clone()){}
|
||||
else if let Some(it) = ast::ImplDef::cast((container).clone()){}
|
||||
if let Some(it) = ast::TraitDef::cast(container.clone()){}
|
||||
else if let Some(it) = ast::ImplDef::cast(container.clone()){}
|
||||
else {
|
||||
{
|
||||
continue
|
||||
|
@ -15,6 +15,7 @@
|
||||
//! cell: copy, drop
|
||||
//! clone: sized
|
||||
//! coerce_unsized: unsize
|
||||
//! concat:
|
||||
//! copy: clone
|
||||
//! default: sized
|
||||
//! deref_mut: deref
|
||||
@ -1353,7 +1354,7 @@ mod panicking {
|
||||
mod macros {
|
||||
// region:panic
|
||||
#[macro_export]
|
||||
#[rustc_builtin_macro(std_panic)]
|
||||
#[rustc_builtin_macro(core_panic)]
|
||||
macro_rules! panic {
|
||||
($($arg:tt)*) => {
|
||||
/* compiler built-in */
|
||||
@ -1406,6 +1407,12 @@ mod macros {
|
||||
($file:expr $(,)?) => {{ /* compiler built-in */ }};
|
||||
}
|
||||
// endregion:include
|
||||
|
||||
// region:concat
|
||||
#[rustc_builtin_macro]
|
||||
#[macro_export]
|
||||
macro_rules! concat {}
|
||||
// endregion:concat
|
||||
}
|
||||
|
||||
// region:non_zero
|
||||
|
Loading…
Reference in New Issue
Block a user