Auto merge of #149195 - petrochenkov:globamberr, r= · rust-lang/rust@9cbe924 (original) (raw)

`@@ -325,7 +325,6 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {

`

325

325

`self.arenas.alloc_name_binding(NameBindingData {

`

326

326

`kind: NameBindingKind::Import { binding, import },

`

327

327

`ambiguity: None,

`

328

``

`-

warn_ambiguity: false,

`

329

328

`span: import.span,

`

330

329

` vis,

`

331

330

`expansion: import.parent_scope.expansion,

`

`@@ -339,7 +338,6 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {

`

339

338

`ident: Ident,

`

340

339

`ns: Namespace,

`

341

340

`binding: NameBinding<'ra>,

`

342

``

`-

warn_ambiguity: bool,

`

343

341

`) -> Result<(), NameBinding<'ra>> {

`

344

342

`let res = binding.res();

`

345

343

`self.check_reserved_macro_name(ident, res);

`

`@@ -351,7 +349,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {

`

351

349

` module.underscore_disambiguator.update_unchecked(|d| d + 1);

`

352

350

` module.underscore_disambiguator.get()

`

353

351

`});

`

354

``

`-

self.update_local_resolution(module, key, warn_ambiguity, |this, resolution| {

`

``

352

`+

self.update_local_resolution(module, key, |this, resolution| {

`

355

353

`if let Some(old_binding) = resolution.best_binding() {

`

356

354

`if res == Res::Err && old_binding.res() != Res::Err {

`

357

355

`` // Do not override real bindings with Res::Errs from error recovery.

``

`@@ -360,30 +358,31 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {

`

360

358

`match (old_binding.is_glob_import(), binding.is_glob_import()) {

`

361

359

`(true, true) => {

`

362

360

`let (glob_binding, old_glob_binding) = (binding, old_binding);

`

363

``

`` -

// FIXME: remove !binding.is_ambiguity_recursive() after delete the warning ambiguity.

``

364

``

`-

if !binding.is_ambiguity_recursive()

`

365

``

`-

&& let NameBindingKind::Import { import: old_import, .. } =

`

366

``

`-

old_glob_binding.kind

`

367

``

`-

&& let NameBindingKind::Import { import, .. } = glob_binding.kind

`

368

``

`-

&& old_import == import

`

369

``

`-

{

`

370

``

`-

// When imported from the same glob-import statement, we should replace

`

371

``

`` -

// old_glob_binding with glob_binding, regardless of whether

``

372

``

`-

// they have the same resolution or not.

`

373

``

`-

resolution.glob_binding = Some(glob_binding);

`

374

``

`-

} else if res != old_glob_binding.res() {

`

``

361

`+

if res != old_glob_binding.res() {

`

``

362

`+

let (primary_binding, secondary_binding, warning) = if !binding

`

``

363

`+

.is_ambiguity_recursive()

`

``

364

`+

&& let NameBindingKind::Import { import: old_import, .. } =

`

``

365

`+

old_glob_binding.kind

`

``

366

`+

&& let NameBindingKind::Import { import, .. } = glob_binding.kind

`

``

367

`+

&& old_import == import

`

``

368

`+

{

`

``

369

`+

// When imported from the same import, we have to replace

`

``

370

`` +

// old_glob_binding with glob_binding to avoid cascade errors.

``

``

371

`+

(glob_binding, old_glob_binding, true)

`

``

372

`+

} else {

`

``

373

`+

(old_glob_binding, glob_binding, false)

`

``

374

`+

};

`

375

375

` resolution.glob_binding = Some(this.new_ambiguity_binding(

`

376

376

`AmbiguityKind::GlobVsGlob,

`

377

``

`-

old_glob_binding,

`

378

``

`-

glob_binding,

`

379

``

`-

warn_ambiguity,

`

``

377

`+

primary_binding,

`

``

378

`+

secondary_binding,

`

``

379

`+

warning,

`

380

380

`));

`

381

``

`-

} else if !old_binding.vis.is_at_least(binding.vis, this.tcx) {

`

``

381

`+

} else if !old_glob_binding.vis.is_at_least(glob_binding.vis, this.tcx)

`

``

382

`+

|| glob_binding.is_ambiguity_recursive()

`

``

383

`+

{

`

382

384

`// We are glob-importing the same item but with greater visibility.

`

383

385

` resolution.glob_binding = Some(glob_binding);

`

384

``

`-

} else if binding.is_ambiguity_recursive() {

`

385

``

`-

resolution.glob_binding =

`

386

``

`-

Some(this.new_warn_ambiguity_binding(glob_binding));

`

387

386

`}

`

388

387

`}

`

389

388

`(old_glob @ true, false) | (old_glob @ false, true) => {

`

`@@ -412,7 +411,10 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {

`

412

411

` glob_binding,

`

413

412

`false,

`

414

413

`));

`

415

``

`-

} else if !old_glob_binding.vis.is_at_least(binding.vis, this.tcx) {

`

``

414

`+

} else if !old_glob_binding.vis.is_at_least(glob_binding.vis, this.tcx)

`

``

415

`+

|| glob_binding.is_ambiguity_recursive()

`

``

416

`+

{

`

``

417

`+

// We are glob-importing the same item but with greater visibility.

`

416

418

` resolution.glob_binding = Some(glob_binding);

`

417

419

`}

`

418

420

`} else {

`

`@@ -440,33 +442,22 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {

`

440

442

`ambiguity_kind: AmbiguityKind,

`

441

443

`primary_binding: NameBinding<'ra>,

`

442

444

`secondary_binding: NameBinding<'ra>,

`

443

``

`-

warn_ambiguity: bool,

`

``

445

`+

warning: bool,

`

444

446

`) -> NameBinding<'ra> {

`

445

``

`-

let ambiguity = Some((secondary_binding, ambiguity_kind));

`

446

``

`-

let data = NameBindingData { ambiguity, warn_ambiguity, ..*primary_binding };

`

``

447

`+

let ambiguity = Some((secondary_binding, ambiguity_kind, warning));

`

``

448

`+

let data = NameBindingData { ambiguity, ..*primary_binding };

`

447

449

`self.arenas.alloc_name_binding(data)

`

448

450

`}

`

449

451

``

450

``

`-

fn new_warn_ambiguity_binding(&self, binding: NameBinding<'ra>) -> NameBinding<'ra> {

`

451

``

`-

assert!(binding.is_ambiguity_recursive());

`

452

``

`-

self.arenas.alloc_name_binding(NameBindingData { warn_ambiguity: true, ..*binding })

`

453

``

`-

}

`

454

``

-

455

452

`` // Use f to mutate the resolution of the name in the module.

``

456

453

`// If the resolution becomes a success, define it in the module's glob importers.

`

457

``

`-

fn update_local_resolution<T, F>(

`

458

``

`-

&mut self,

`

459

``

`-

module: Module<'ra>,

`

460

``

`-

key: BindingKey,

`

461

``

`-

warn_ambiguity: bool,

`

462

``

`-

f: F,

`

463

``

`-

) -> T

`

``

454

`+

fn update_local_resolution<T, F>(&mut self, module: Module<'ra>, key: BindingKey, f: F) -> T

`

464

455

`where

`

465

456

`F: FnOnce(&Resolver<'ra, 'tcx>, &mut NameResolution<'ra>) -> T,

`

466

457

`{

`

467

458

`` // Ensure that resolution isn't borrowed when defining in the module's glob importers,

``

468

459

`// during which the resolution might end up getting re-defined via a glob cycle.

`

469

``

`-

let (binding, t, warn_ambiguity) = {

`

``

460

`+

let (binding, t) = {

`

470

461

`let resolution = &mut *self.resolution_or_default(module, key).borrow_mut_unchecked();

`

471

462

`let old_binding = resolution.binding();

`

472

463

``

`@@ -475,7 +466,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {

`

475

466

`if let Some(binding) = resolution.binding()

`

476

467

` && old_binding != Some(binding)

`

477

468

`{

`

478

``

`-

(binding, t, warn_ambiguity || old_binding.is_some())

`

``

469

`+

(binding, t)

`

479

470

`} else {

`

480

471

`return t;

`

481

472

`}

`

`@@ -500,7 +491,6 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {

`

500

491

` ident.0,

`

501

492

` key.ns,

`

502

493

` imported_binding,

`

503

``

`-

warn_ambiguity,

`

504

494

`);

`

505

495

`}

`

506

496

`}

`

`@@ -521,11 +511,11 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {

`

521

511

`let dummy_binding = self.import(dummy_binding, import);

`

522

512

`self.per_ns(|this, ns| {

`

523

513

`let module = import.parent_scope.module;

`

524

``

`-

let _ = this.try_define_local(module, target, ns, dummy_binding, false);

`

``

514

`+

let _ = this.try_define_local(module, target, ns, dummy_binding);

`

525

515

`` // Don't remove underscores from single_imports, they were never added.

``

526

516

`if target.name != kw::Underscore {

`

527

517

`let key = BindingKey::new(target, ns);

`

528

``

`-

this.update_local_resolution(module, key, false, |_, resolution| {

`

``

518

`+

this.update_local_resolution(module, key, |_, resolution| {

`

529

519

` resolution.single_imports.swap_remove(&import);

`

530

520

`})

`

531

521

`}

`

`@@ -658,7 +648,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {

`

658

648

`let Some(binding) = resolution.best_binding() else { continue };

`

659

649

``

660

650

`if let NameBindingKind::Import { import, .. } = binding.kind

`

661

``

`-

&& let Some((amb_binding, _)) = binding.ambiguity

`

``

651

`+

&& let Some((amb_binding, ..)) = binding.ambiguity

`

662

652

` && binding.res() != Res::Err

`

663

653

` && exported_ambiguities.contains(&binding)

`

664

654

`{

`

`@@ -917,7 +907,6 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {

`

917

907

` this.get_mut_unchecked().update_local_resolution(

`

918

908

` parent,

`

919

909

` key,

`

920

``

`-

false,

`

921

910

` |_, resolution| {

`

922

911

` resolution.single_imports.swap_remove(&import);

`

923

912

`},

`

`@@ -1523,16 +1512,11 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {

`

1523

1512

`};

`

1524

1513

`if self.is_accessible_from(binding.vis, scope) {

`

1525

1514

`let imported_binding = self.import(binding, import);

`

1526

``

`-

let warn_ambiguity = self

`

1527

``

`-

.resolution(import.parent_scope.module, key)

`

1528

``

`-

.and_then(|r| r.binding())

`

1529

``

`-

.is_some_and(|binding| binding.warn_ambiguity_recursive());

`

1530

1515

`let _ = self.try_define_local(

`

1531

1516

` import.parent_scope.module,

`

1532

1517

` key.ident.0,

`

1533

1518

` key.ns,

`

1534

1519

` imported_binding,

`

1535

``

`-

warn_ambiguity,

`

1536

1520

`);

`

1537

1521

`}

`

1538

1522

`}

`