Auto merge of #125576 - lnicola:sync-from-ra, r=lnicola · rust-lang/rust@0aad3f6

92 files changed

lines changed

Original file line numberDiff line numberDiff line change

@@ -12,9 +12,6 @@ use std::sync::OnceLock;

1212
1313

use rustc_hash::FxHashMap;

1414
15-

/// Ignored attribute namespaces used by tools.

16-

pub const TOOL_MODULES: &[&str] = &["rustfmt", "clippy"];

17-
1815

pub struct BuiltinAttribute {

1916

pub name: &'static str,

2017

pub template: AttributeTemplate,

Original file line numberDiff line numberDiff line change

@@ -17,7 +17,7 @@ use syntax::{

1717

self, ArrayExprKind, AstChildren, BlockExpr, HasArgList, HasAttrs, HasLoopBody, HasName,

1818

RangeItem, SlicePatComponents,

1919

},

20-

AstNode, AstPtr, SyntaxNodePtr,

20+

AstNode, AstPtr, AstToken as _, SyntaxNodePtr,

2121

};

2222

use triomphe::Arc;

2323

@@ -1577,7 +1577,13 @@ impl ExprCollector<'_> {

15771577

});

15781578

});

15791579

let template = f.template();

1580-

let fmt_snippet = template.as_ref().map(ToString::to_string);

1580+

let fmt_snippet = template.as_ref().and_then(|it| match it {

1581+

ast::Expr::Literal(literal) => match literal.kind() {

1582+

ast::LiteralKind::String(s) => Some(s.text().to_owned()),

1583+

_ => None,

1584+

},

1585+

_ => None,

1586+

});

15811587

let mut mappings = vec![];

15821588

let fmt = match template.and_then(|it| self.expand_macros_to_string(it)) {

15831589

Some((s, is_direct_literal)) => format_args::parse(

Original file line numberDiff line numberDiff line change

@@ -150,7 +150,7 @@ fn desugar_builtin_format_args() {

150150

fn main() {

151151

let are = "are";

152152

let count = 10;

153-

builtin#format_args("hello {count:02} {} friends, we {are:?} {0}{last}", "fancy", last = "!");

153+

builtin#format_args("\u{1b}hello {count:02} {} friends, we {are:?} {0}{last}", "fancy", last = "!");

154154

}

155155

"#,

156156

);

@@ -161,7 +161,7 @@ fn main() {

161161

let count = 10;

162162

builtin#lang(Arguments::new_v1_formatted)(

163163

&[

164-

"hello ", " ", " friends, we ", " ", "",

164+

"\u{1b}hello ", " ", " friends, we ", " ", "",

165165

],

166166

&[

167167

builtin#lang(Argument::new_display)(

Original file line numberDiff line numberDiff line change

@@ -528,3 +528,65 @@ fn f() {$0

528528

"#]],

529529

)

530530

}

531+
532+

#[test]

533+

fn resolve_extern_prelude_in_block() {

534+

check_at(

535+

r#"

536+

//- /main.rs crate:main deps:core

537+

fn main() {

538+

mod f {

539+

use core::S;

540+

$0

541+

}

542+

}

543+
544+

//- /core.rs crate:core

545+

pub struct S;

546+

"#,

547+

expect![[r#"

548+

block scope

549+

f: t

550+
551+

block scope::f

552+

S: ti vi

553+
554+

crate

555+

main: v

556+

"#]],

557+

)

558+

}

559+
560+

#[test]

561+

fn shadow_extern_prelude_in_block() {

562+

check_at(

563+

r#"

564+

//- /main.rs crate:main deps:core

565+

fn main() {

566+

mod core { pub struct S; }

567+

{

568+

fn inner() {} // forces a block def map

569+

use core::S; // should resolve to the local one

570+

$0

571+

}

572+

}

573+
574+

//- /core.rs crate:core

575+

pub const S;

576+

"#,

577+

expect![[r#"

578+

block scope

579+

S: ti vi

580+

inner: v

581+
582+

block scope

583+

core: t

584+
585+

block scope::core

586+

S: t v

587+
588+

crate

589+

main: v

590+

"#]],

591+

)

592+

}