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

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

`

326

326

`self.arenas.alloc_name_binding(NameBindingData {

`

327

327

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

`

328

328

`ambiguity: None,

`

329

``

`-

warn_ambiguity: false,

`

330

329

`span: import.span,

`

331

330

` vis,

`

332

331

`expansion: import.parent_scope.expansion,

`

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

`

340

339

`ident: Ident,

`

341

340

`ns: Namespace,

`

342

341

`binding: NameBinding<'ra>,

`

343

``

`-

warn_ambiguity: bool,

`

344

342

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

`

345

343

`let res = binding.res();

`

346

344

`self.check_reserved_macro_name(ident, res);

`

`@@ -352,7 +350,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {

`

352

350

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

`

353

351

` module.underscore_disambiguator.get()

`

354

352

`});

`

355

``

`-

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

`

``

353

`+

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

`

356

354

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

`

357

355

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

`

358

356

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

``

`@@ -361,30 +359,17 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {

`

361

359

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

`

362

360

`(true, true) => {

`

363

361

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

`

364

``

`` -

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

``

365

``

`-

if !binding.is_ambiguity_recursive()

`

366

``

`-

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

`

367

``

`-

old_glob_binding.kind

`

368

``

`-

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

`

369

``

`-

&& old_import == import

`

370

``

`-

{

`

371

``

`-

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

`

372

``

`` -

// old_glob_binding with glob_binding, regardless of whether

``

373

``

`-

// they have the same resolution or not.

`

374

``

`-

resolution.glob_binding = Some(glob_binding);

`

375

``

`-

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

`

``

362

`+

if res != old_glob_binding.res() {

`

376

363

` resolution.glob_binding = Some(this.new_ambiguity_binding(

`

377

364

`AmbiguityKind::GlobVsGlob,

`

378

365

` old_glob_binding,

`

379

366

` glob_binding,

`

380

``

`-

warn_ambiguity,

`

381

367

`));

`

382

``

`-

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

`

``

368

`+

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

`

``

369

`+

|| glob_binding.is_ambiguity_recursive()

`

``

370

`+

{

`

383

371

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

`

384

372

` resolution.glob_binding = Some(glob_binding);

`

385

``

`-

} else if binding.is_ambiguity_recursive() {

`

386

``

`-

resolution.glob_binding =

`

387

``

`-

Some(this.new_warn_ambiguity_binding(glob_binding));

`

388

373

`}

`

389

374

`}

`

390

375

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

`

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

`

398

383

`AmbiguityKind::GlobVsExpanded,

`

399

384

` non_glob_binding,

`

400

385

` glob_binding,

`

401

``

`-

false,

`

402

386

`));

`

403

387

`} else {

`

404

388

` resolution.non_glob_binding = Some(non_glob_binding);

`

`@@ -411,9 +395,11 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {

`

411

395

`AmbiguityKind::GlobVsGlob,

`

412

396

` old_glob_binding,

`

413

397

` glob_binding,

`

414

``

`-

false,

`

415

398

`));

`

416

``

`-

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

`

``

399

`+

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

`

``

400

`+

|| glob_binding.is_ambiguity_recursive()

`

``

401

`+

{

`

``

402

`+

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

`

417

403

` resolution.glob_binding = Some(glob_binding);

`

418

404

`}

`

419

405

`} else {

`

`@@ -441,33 +427,21 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {

`

441

427

`ambiguity_kind: AmbiguityKind,

`

442

428

`primary_binding: NameBinding<'ra>,

`

443

429

`secondary_binding: NameBinding<'ra>,

`

444

``

`-

warn_ambiguity: bool,

`

445

430

`) -> NameBinding<'ra> {

`

446

431

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

`

447

``

`-

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

`

``

432

`+

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

`

448

433

`self.arenas.alloc_name_binding(data)

`

449

434

`}

`

450

435

``

451

``

`-

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

`

452

``

`-

assert!(binding.is_ambiguity_recursive());

`

453

``

`-

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

`

454

``

`-

}

`

455

``

-

456

436

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

``

457

437

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

`

458

``

`-

fn update_local_resolution<T, F>(

`

459

``

`-

&mut self,

`

460

``

`-

module: Module<'ra>,

`

461

``

`-

key: BindingKey,

`

462

``

`-

warn_ambiguity: bool,

`

463

``

`-

f: F,

`

464

``

`-

) -> T

`

``

438

`+

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

`

465

439

`where

`

466

440

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

`

467

441

`{

`

468

442

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

``

469

443

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

`

470

``

`-

let (binding, t, warn_ambiguity) = {

`

``

444

`+

let (binding, t) = {

`

471

445

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

`

472

446

`let old_binding = resolution.binding();

`

473

447

``

`@@ -476,7 +450,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {

`

476

450

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

`

477

451

` && old_binding != Some(binding)

`

478

452

`{

`

479

``

`-

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

`

``

453

`+

(binding, t)

`

480

454

`} else {

`

481

455

`return t;

`

482

456

`}

`

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

`

501

475

` ident.0,

`

502

476

` key.ns,

`

503

477

` imported_binding,

`

504

``

`-

warn_ambiguity,

`

505

478

`);

`

506

479

`}

`

507

480

`}

`

`@@ -522,11 +495,11 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {

`

522

495

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

`

523

496

`self.per_ns(|this, ns| {

`

524

497

`let module = import.parent_scope.module;

`

525

``

`-

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

`

``

498

`+

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

`

526

499

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

``

527

500

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

`

528

501

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

`

529

``

`-

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

`

``

502

`+

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

`

530

503

` resolution.single_imports.swap_remove(&import);

`

531

504

`})

`

532

505

`}

`

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

`

916

889

` this.get_mut_unchecked().update_local_resolution(

`

917

890

` parent,

`

918

891

` key,

`

919

``

`-

false,

`

920

892

` |_, resolution| {

`

921

893

` resolution.single_imports.swap_remove(&import);

`

922

894

`},

`

`@@ -945,8 +917,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {

`

945

917

`ImportKind::Single { bindings, .. } => bindings[TypeNS].get().binding(),

`

946

918

` _ => None,

`

947

919

`};

`

948

``

`-

let ambiguity_errors_len =

`

949

``

`-

|errors: &Vec<AmbiguityError<'_>>| errors.iter().filter(|error| !error.warning).count();

`

``

920

`+

let ambiguity_errors_len = |errors: &Vec<AmbiguityError<'_>>| errors.iter().count();

`

950

921

`let prev_ambiguity_errors_len = ambiguity_errors_len(&self.ambiguity_errors);

`

951

922

`let finalize = Finalize::with_root_span(import.root_id, import.span, import.root_span);

`

952

923

``

`@@ -1160,9 +1131,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {

`

1160

1131

` initial_binding.res()

`

1161

1132

`});

`

1162

1133

`let res = binding.res();

`

1163

``

`-

let has_ambiguity_error =

`

1164

``

`-

this.ambiguity_errors.iter().any(|error| !error.warning);

`

1165

``

`-

if res == Res::Err || has_ambiguity_error {

`

``

1134

`+

if res == Res::Err || !this.ambiguity_errors.is_empty() {

`

1166

1135

` this.dcx()

`

1167

1136

`.span_delayed_bug(import.span, "some error happened for an import");

`

1168

1137

`return;

`

`@@ -1520,16 +1489,11 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {

`

1520

1489

`};

`

1521

1490

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

`

1522

1491

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

`

1523

``

`-

let warn_ambiguity = self

`

1524

``

`-

.resolution(import.parent_scope.module, key)

`

1525

``

`-

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

`

1526

``

`-

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

`

1527

1492

`let _ = self.try_define_local(

`

1528

1493

` import.parent_scope.module,

`

1529

1494

` key.ident.0,

`

1530

1495

` key.ns,

`

1531

1496

` imported_binding,

`

1532

``

`-

warn_ambiguity,

`

1533

1497

`);

`

1534

1498

`}

`

1535

1499

`}

`

`@@ -1554,8 +1518,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {

`

1554

1518

``

1555

1519

` module.for_each_child(self, |this, ident, _, binding| {

`

1556

1520

`let res = binding.res().expect_non_local();

`

1557

``

`-

let error_ambiguity = binding.is_ambiguity_recursive() && !binding.warn_ambiguity;

`

1558

``

`-

if res != def::Res::Err && !error_ambiguity {

`

``

1521

`+

if res != def::Res::Err && !binding.is_ambiguity_recursive() {

`

1559

1522

`let mut reexport_chain = SmallVec::new();

`

1560

1523

`let mut next_binding = binding;

`

1561

1524

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

`