Auto merge of #135846 - estebank:non-exhaustive-dfv-ctor-2, r= · rust-lang/rust@5e87c8e (original) (raw)

`@@ -403,7 +403,7 @@ pub(crate) enum PathSource<'a> {

`

403

403

`` // Paths in path patterns Path.

``

404

404

`Pat,

`

405

405

`` // Paths in struct expressions and patterns Path { .. }.

``

406

``

`-

Struct,

`

``

406

`+

Struct(Option<&'a Expr>),

`

407

407

`` // Paths in tuple struct patterns Path(..).

``

408

408

`TupleStruct(Span, &'a [Span]),

`

409

409

`` // m::A::B in <T as m::A>::B::C.

``

`@@ -419,7 +419,7 @@ pub(crate) enum PathSource<'a> {

`

419

419

`impl<'a> PathSource<'a> {

`

420

420

`fn namespace(self) -> Namespace {

`

421

421

`match self {

`

422

``

`-

PathSource::Type | PathSource::Trait(_) | PathSource::Struct => TypeNS,

`

``

422

`+

PathSource::Type | PathSource::Trait() | PathSource::Struct() => TypeNS,

`

423

423

`PathSource::Expr(..)

`

424

424

` | PathSource::Pat

`

425

425

` | PathSource::TupleStruct(..)

`

`@@ -435,7 +435,7 @@ impl<'a> PathSource<'a> {

`

435

435

`PathSource::Type

`

436

436

` | PathSource::Expr(..)

`

437

437

` | PathSource::Pat

`

438

``

`-

| PathSource::Struct

`

``

438

`+

| PathSource::Struct(_)

`

439

439

` | PathSource::TupleStruct(..)

`

440

440

` | PathSource::ReturnTypeNotation => true,

`

441

441

`PathSource::Trait(_)

`

`@@ -450,7 +450,7 @@ impl<'a> PathSource<'a> {

`

450

450

`PathSource::Type => "type",

`

451

451

`PathSource::Trait(_) => "trait",

`

452

452

`PathSource::Pat => "unit struct, unit variant or constant",

`

453

``

`-

PathSource::Struct => "struct, variant or union type",

`

``

453

`+

PathSource::Struct(_) => "struct, variant or union type",

`

454

454

`PathSource::TupleStruct(..) => "tuple struct or tuple variant",

`

455

455

`PathSource::TraitItem(ns) => match ns {

`

456

456

`TypeNS => "associated type",

`

`@@ -531,7 +531,7 @@ impl<'a> PathSource<'a> {

`

531

531

` || matches!(res, Res::Def(DefKind::Const | DefKind::AssocConst, _))

`

532

532

`}

`

533

533

`PathSource::TupleStruct(..) => res.expected_in_tuple_struct_pat(),

`

534

``

`-

PathSource::Struct => matches!(

`

``

534

`+

PathSource::Struct(_) => matches!(

`

535

535

` res,

`

536

536

`Res::Def(

`

537

537

`DefKind::Struct

`

`@@ -571,8 +571,8 @@ impl<'a> PathSource<'a> {

`

571

571

`(PathSource::Trait(_), false) => E0405,

`

572

572

`(PathSource::Type, true) => E0573,

`

573

573

`(PathSource::Type, false) => E0412,

`

574

``

`-

(PathSource::Struct, true) => E0574,

`

575

``

`-

(PathSource::Struct, false) => E0422,

`

``

574

`+

(PathSource::Struct(_), true) => E0574,

`

``

575

`+

(PathSource::Struct(_), false) => E0422,

`

576

576

`(PathSource::Expr(..), true) | (PathSource::Delegation, true) => E0423,

`

577

577

`(PathSource::Expr(..), false) | (PathSource::Delegation, false) => E0425,

`

578

578

`(PathSource::Pat | PathSource::TupleStruct(..), true) => E0532,

`

`@@ -1454,11 +1454,13 @@ impl<'a, 'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {

`

1454

1454

`path: &[Segment],

`

1455

1455

`` opt_ns: Option, // None indicates a module path in import

``

1456

1456

`finalize: Option,

`

``

1457

`+

source: PathSource<'ast>,

`

1457

1458

`) -> PathResult<'ra> {

`

1458

1459

`self.r.resolve_path_with_ribs(

`

1459

1460

` path,

`

1460

1461

` opt_ns,

`

1461

1462

`&self.parent_scope,

`

``

1463

`+

Some(source),

`

1462

1464

` finalize,

`

1463

1465

`Some(&self.ribs),

`

1464

1466

`None,

`

`@@ -1961,7 +1963,7 @@ impl<'a, 'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {

`

1961

1963

` | PathSource::ReturnTypeNotation => false,

`

1962

1964

`PathSource::Expr(..)

`

1963

1965

` | PathSource::Pat

`

1964

``

`-

| PathSource::Struct

`

``

1966

`+

| PathSource::Struct(_)

`

1965

1967

` | PathSource::TupleStruct(..)

`

1966

1968

` | PathSource::Delegation => true,

`

1967

1969

`};

`

`@@ -3794,7 +3796,7 @@ impl<'a, 'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {

`

3794

3796

`self.smart_resolve_path(pat.id, qself, path, PathSource::Pat);

`

3795

3797

`}

`

3796

3798

`PatKind::Struct(ref qself, ref path, ref _fields, ref rest) => {

`

3797

``

`-

self.smart_resolve_path(pat.id, qself, path, PathSource::Struct);

`

``

3799

`+

self.smart_resolve_path(pat.id, qself, path, PathSource::Struct(None));

`

3798

3800

`self.record_patterns_with_skipped_bindings(pat, rest);

`

3799

3801

`}

`

3800

3802

`PatKind::Or(ref ps) => {

`

`@@ -4200,6 +4202,7 @@ impl<'a, 'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {

`

4200

4202

` qself,

`

4201

4203

` path,

`

4202

4204

` ns,

`

``

4205

`+

source,

`

4203

4206

` path_span,

`

4204

4207

` source.defer_to_typeck(),

`

4205

4208

` finalize,

`

`@@ -4245,7 +4248,7 @@ impl<'a, 'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {

`

4245

4248

` std_path.push(Segment::from_ident(Ident::with_dummy_span(sym::std)));

`

4246

4249

` std_path.extend(path);

`

4247

4250

`if let PathResult::Module() | PathResult::NonModule() =

`

4248

``

`-

self.resolve_path(&std_path, Some(ns), None)

`

``

4251

`+

self.resolve_path(&std_path, Some(ns), None, source)

`

4249

4252

`{

`

4250

4253

`` // Check if we wrote str::from_utf8 instead of std::str::from_utf8

``

4251

4254

`let item_span =

`

`@@ -4316,6 +4319,7 @@ impl<'a, 'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {

`

4316

4319

`qself: &Option<P>,

`

4317

4320

`path: &[Segment],

`

4318

4321

`primary_ns: Namespace,

`

``

4322

`+

source: PathSource<'ast>,

`

4319

4323

`span: Span,

`

4320

4324

`defer_to_typeck: bool,

`

4321

4325

`finalize: Finalize,

`

`@@ -4324,7 +4328,7 @@ impl<'a, 'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {

`

4324

4328

``

4325

4329

`for (i, &ns) in [primary_ns, TypeNS, ValueNS].iter().enumerate() {

`

4326

4330

`if i == 0 || ns != primary_ns {

`

4327

``

`-

match self.resolve_qpath(qself, path, ns, finalize)? {

`

``

4331

`+

match self.resolve_qpath(qself, path, ns, source, finalize)? {

`

4328

4332

`Some(partial_res)

`

4329

4333

`if partial_res.unresolved_segments() == 0 || defer_to_typeck =>

`

4330

4334

`{

`

`@@ -4360,6 +4364,7 @@ impl<'a, 'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {

`

4360

4364

`qself: &Option<P>,

`

4361

4365

`path: &[Segment],

`

4362

4366

`ns: Namespace,

`

``

4367

`+

source: PathSource<'ast>,

`

4363

4368

`finalize: Finalize,

`

4364

4369

`) -> Result<Option, Spanned<ResolutionError<'ra>>> {

`

4365

4370

`debug!(

`

`@@ -4421,7 +4426,7 @@ impl<'a, 'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {

`

4421

4426

`)));

`

4422

4427

`}

`

4423

4428

``

4424

``

`-

let result = match self.resolve_path(path, Some(ns), Some(finalize)) {

`

``

4429

`+

let result = match self.resolve_path(path, Some(ns), Some(finalize), source) {

`

4425

4430

`PathResult::NonModule(path_res) => path_res,

`

4426

4431

`PathResult::Module(ModuleOrUniformRoot::Module(module)) if !module.is_normal() => {

`

4427

4432

`PartialRes::new(module.res().unwrap())

`

`@@ -4642,7 +4647,7 @@ impl<'a, 'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {

`

4642

4647

`}

`

4643

4648

``

4644

4649

`ExprKind::Struct(ref se) => {

`

4645

``

`-

self.smart_resolve_path(expr.id, &se.qself, &se.path, PathSource::Struct);

`

``

4650

`+

self.smart_resolve_path(expr.id, &se.qself, &se.path, PathSource::Struct(parent));

`

4646

4651

`` // This is the same as visit::walk_expr(self, expr);, but we want to pass the

``

4647

4652

`` // parent in for accurate suggestions when encountering Foo { bar } that should

``

4648

4653

`` // have been Foo { bar: self.bar }.

``